Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KrithihaRaja - abc bank #322

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions my-bank-master (1)/my-bank-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Programming Test
========

This is a dummy application to be used as part of a software development interview.

instructions
--------

* Treat this code as if you owned this application, do whatever you feel is necessary to make this your own.
* There are several deliberate design, code quality and test issues that should be identified and resolved.
* Below is a list of the current features supported by the application; as well as some additional features that have been requested by the business owner.
* In order to work on this take a fork into your own GitHub area; make whatever changes you feel are necessary and when you are satisfied submit back via a pull request. See details on GitHub's [Fork & Pull](https://help.github.com/articles/using-pull-requests) model
* Be sure to put your name in the pull request comment so your work can be easily identied.
* The project uses maven to resolve dependencies however if you want to avoid maven configuration the only external JAR that's required is junit-4.11.
* Refactor and add features (from the below list) as you see fit; there is no need to add all the features in order to "complete" the exercise. Keep in mind that code quality is the critical measure and there should be an obvious focus on testing.
* You'll notice there is no database or UI; these are not needed - the exercise deliberately avoids these requirements.
* REMEMBER: this is YOUR code, make any changes you feel are necessary.
* You're welcome to spend as much time as you like.
* The code will be a representation of your work, so it's important that all the code--new and pre-existing--is how you want your work to be seen. Please make sure that you are happy with ALL the code.

abc-bank
--------

A dummy application for a bank; should provide various functions of a retail bank.

### Current Features

* A customer can open an account
* A customer can deposit / withdraw funds from an account
* A customer can request a statement that shows transactions and totals for each of their accounts
* Different accounts have interest calculated in different ways
* **Checking accounts** have a flat rate of 0.1%
* **Savings accounts** have a rate of 0.1% for the first $1,000 then 0.2%
* **Maxi-Savings accounts** have a rate of 2% for the first $1,000 then 5% for the next $1,000 then 10%
* A bank manager can get a report showing the list of customers and how many accounts they have
* A bank manager can get a report showing the total interest paid by the bank on all accounts

### Additional Features

* A customer can transfer between their accounts
* Change **Maxi-Savings accounts** to have an interest rate of 5% assuming no withdrawals in the past 10 days otherwise 0.1%
* Interest rates should accrue and compound daily (incl. weekends), rates above are per-annum
24 changes: 24 additions & 0 deletions my-bank-master (1)/my-bank-master/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.abc</groupId>
<artifactId>bank</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>bank</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.abc;

import java.util.ArrayList;
import java.util.List;

public class Account {

public static final int CHECKING = 0;
public static final int SAVINGS = 1;
public static final int MAXI_SAVINGS = 2;

private final int accountType;
public List<Transaction> transactions;

public Account(int accountType) {
this.accountType = accountType;
this.transactions = new ArrayList<Transaction>();
}

public void deposit(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be greater than zero");
} else {
transactions.add(new Transaction(amount));
}
}

public void withdraw(double amount) {
if (amount <= 0) {
throw new IllegalArgumentException("amount must be greater than zero");
} else {
transactions.add(new Transaction(-amount));
}
}

public double interestEarned() {
double amount = sumTransactions();
switch(accountType){
case SAVINGS:
if (amount <= 1000)
return amount * 0.001;
else
return 1 + (amount-1000) * 0.002;
// case SUPER_SAVINGS:
// if (amount <= 4000)
// return 20;
case MAXI_SAVINGS:
if (amount <= 1000)
return amount * 0.02;
if (amount <= 2000)
return 20 + (amount-1000) * 0.05;
return 70 + (amount-2000) * 0.1;
default:
return amount * 0.001;
}
}

public double sumTransactions() {
return checkIfTransactionsExist(true);
}

private double checkIfTransactionsExist(boolean checkAll) {
double amount = 0.0;
for (Transaction t: transactions)
amount += t.amount;
return amount;
}

public int getAccountType() {
return accountType;
}

public List<Transaction> getTransactions() {
return transactions;
}

public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}

}
46 changes: 46 additions & 0 deletions my-bank-master (1)/my-bank-master/src/main/java/com/abc/Bank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.abc;

import java.util.ArrayList;
import java.util.List;

public class Bank {
private List<Customer> customers;

public Bank() {
customers = new ArrayList<Customer>();
}

public void addCustomer(Customer customer) {
customers.add(customer);
}

public String customerSummary() {
String summary = "Customer Summary";
for (Customer c : customers)
summary += "\n - " + c.getName() + " (" + format(c.getNumberOfAccounts(), "account") + ")";
return summary;
}

//Make sure correct plural of word is created based on the number passed in:
//If number passed in is 1 just return the word otherwise add an 's' at the end
private String format(int number, String word) {
return number + " " + (number == 1 ? word : word + "s");
}

public double totalInterestPaid() {
double total = 0;
for(Customer c: customers)
total += c.totalInterestEarned();
return total;
}

public String getFirstCustomer() {
try {
customers = null;
return customers.get(0).getName();
} catch (Exception e){
e.printStackTrace();
return "Error";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.abc;

import java.util.ArrayList;
import java.util.List;

import static java.lang.Math.abs;

public class Customer {
private String name;
private List<Account> accounts;

public Customer(String name) {
this.name = name;
this.accounts = new ArrayList<Account>();
}

public String getName() {
return name;
}

public Customer openAccount(Account account) {
accounts.add(account);
return this;
}

public int getNumberOfAccounts() {
return accounts.size();
}

public double totalInterestEarned() {
double total = 0;
for (Account a : accounts)
total += a.interestEarned();
return total;
}

public String getStatement() {
String statement = null;
statement = "Statement for " + name + "\n";
double total = 0.0;
for (Account a : accounts) {
statement += "\n" + statementForAccount(a) + "\n";
total += a.sumTransactions();
}
statement += "\nTotal In All Accounts " + toDollars(total);
return statement;
}

private String statementForAccount(Account a) {
String s = "";

//Translate to pretty account type
switch(a.getAccountType()){
case Account.CHECKING:
s += "Checking Account\n";
break;
case Account.SAVINGS:
s += "Savings Account\n";
break;
case Account.MAXI_SAVINGS:
s += "Maxi Savings Account\n";
break;
}

//Now total up all the transactions
double total = 0.0;
for (Transaction t : a.getTransactions()) {
s += " " + (t.amount < 0 ? "withdrawal" : "deposit") + " " + toDollars(t.amount) + "\n";
total += t.amount;
}
s += "Total " + toDollars(total);
return s;
}

private String toDollars(double d){
return String.format("$%,.2f", abs(d));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.abc;

import java.util.Calendar;
import java.util.Date;

public class DateProvider {
private static DateProvider instance = null;

public static DateProvider getInstance() {
if (instance == null)
instance = new DateProvider();
return instance;
}

public Date now() {
return Calendar.getInstance().getTime();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.abc;

import java.util.Calendar;
import java.util.Date;

public class Transaction {
public final double amount;

private Date transactionDate;

public Transaction(double amount) {
this.amount = amount;
this.transactionDate = DateProvider.getInstance().now();
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.abc;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class BankTest {
private static final double DOUBLE_DELTA = 1e-15;

@Test
public void customerSummary() {
Bank bank = new Bank();
Customer john = new Customer("John");
john.openAccount(new Account(Account.CHECKING));
bank.addCustomer(john);

assertEquals("Customer Summary\n - John (1 account)", bank.customerSummary());
}

@Test
public void checkingAccount() {
Bank bank = new Bank();
Account checkingAccount = new Account(Account.CHECKING);
Customer bill = new Customer("Bill").openAccount(checkingAccount);
bank.addCustomer(bill);

checkingAccount.deposit(100.0);

assertEquals(0.1, bank.totalInterestPaid(), DOUBLE_DELTA);
}
@Test
public void maxi_savings_account() {
Bank bank = new Bank();
Account checkingAccount = new Account(Account.MAXI_SAVINGS);
bank.addCustomer(new Customer("Bill").openAccount(checkingAccount));

checkingAccount.deposit(3000.0);

assertEquals(170.0, bank.totalInterestPaid(), DOUBLE_DELTA);
}

@Test
public void savings_account() {
Bank bank = new Bank();
Account checkingAccount = new Account(Account.SAVINGS);
bank.addCustomer(new Customer("Bill").openAccount(checkingAccount));

checkingAccount.deposit(1500.0);

assertEquals(2.0, bank.totalInterestPaid(), DOUBLE_DELTA);
}



}

Loading