Skip to content
This repository was archived by the owner on Dec 29, 2018. It is now read-only.
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
56 changes: 46 additions & 10 deletions src/main/java/Bank.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
*/
public class Bank {

public String bankName;
/**
* Name of the bank.
*/
private String bankName;

/**
* Non-parameterized constructor
*/
public Bank() {
bankName = "Illini Bank";
}
Expand All @@ -26,9 +32,19 @@ public Bank() {
* @return boolean
*/
public boolean withdrawMoney(final BankAccount bankAccount, final double amount) {
/*
* Implement this function
*/
if (amount < 0) {
return false;
}

double currentAmount = bankAccount.getAccountBalance();
double newAmount = currentAmount - amount;

if (newAmount < 0) {
return false;
}
bankAccount.setAccountBalance(newAmount);

return true;
}

/**
Expand All @@ -42,9 +58,15 @@ public boolean withdrawMoney(final BankAccount bankAccount, final double amount)
* @return boolean
*/
public boolean depositMoney(final BankAccount bankAccount, final double amount) {
/*
* Implement this function
*/
if (amount < 0) {
return false;
}

double currentAmount = bankAccount.getAccountBalance();
double newAmount = currentAmount + amount;
bankAccount.setAccountBalance(newAmount);

return true;
}

/**
Expand All @@ -61,9 +83,7 @@ public boolean depositMoney(final BankAccount bankAccount, final double amount)

public boolean transferMoney(final BankAccount source, final BankAccount destination,
final double amount) {
/*
* Implement this function
*/
return (withdrawMoney(source, amount) && depositMoney(destination, amount));
}

/**
Expand All @@ -77,8 +97,12 @@ public void changeOwnerName(final BankAccount bankAccount, final String name) {
/*
* Implement this function
*/
bankAccount.setOwnerName(name);
}

/**
* Number of total accounts.
*/
public static int totalAccounts = 0;
/**
* Uses static variable to get number of bank accounts opened.
Expand All @@ -89,6 +113,7 @@ public static int getNumberOfAccount() {
/*
* Implement this function
*/
return totalAccounts;
}

/**
Expand All @@ -110,14 +135,25 @@ public static void main(final String[] unused) {
System.out.println("Bank account for Johy Ive created\n\n");

// Deposit money to both accounts and print new balance
System.out.println("Add 1000 to acc1, 5000 to ac2");
bank.depositMoney(account1, 1000.0);
System.out.println(account1.getAccountBalance());
bank.depositMoney(account2, 5000.0);
System.out.println(account2.getAccountBalance());
System.out.println();

// Withdraw money from Account 2 and print new balance
System.out.println("Withdraw 200 from acc2");
bank.withdrawMoney(account2, 200.0);
System.out.println(account2.getAccountBalance());
System.out.println();

// Transfer money from Account 2 to Account 1 and print new balances
System.out.println("Send 350 from acc 2 to acc 1");
bank.transferMoney(account2, account1, 350.0);
System.out.println(account1.getAccountBalance());
System.out.println(account2.getAccountBalance());
System.out.println();

// Print number of accounts
System.out.print("Number of active accounts at " + bank.bankName + " are ");
Expand Down
100 changes: 95 additions & 5 deletions src/main/java/BankAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,116 @@ public class BankAccount {
* You may want to use this to distinguish between different kinds of accounts.
*/
public enum BankAccountType {
/**
* Checkings type.
*/
CHECKINGS,

/**
* Savings type.
*/
SAVINGS,

/**
* Student type.
*/
STUDENT,

/**
* Workspace type.
*/
WORKPLACE
}

/**
* Account number.
*/
private int accountNumber;
public BankAccountType accountType;

/**
* Account type.
*/
private BankAccountType accountType;

/**
* Account balance.
*/
private double accountBalance;

/**
* Owner name.
*/
private String ownerName;
public double interestRate;

/**
* Interest rate.
*/
private double interestRate;

/**
* Interest earned.
*/
private double interestEarned;

/**
* Contstructor taking name and account category.
* @param name Name.
* @param accountCategory Account Category
*/
public BankAccount(final String name, final BankAccountType accountCategory) {
/*
* Implement this function
*/
this.ownerName = name;
this.accountType = accountCategory;
Bank.totalAccounts++;
}

/*
* Implement getters and setters as appropriate for private variables.
*/
public int getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}

public BankAccountType getAccountType() {
return accountType;
}

public void setAccountType(BankAccountType accountType) {
this.accountType = accountType;
}

public double getAccountBalance() {
return accountBalance;
}

public void setAccountBalance(double accountBalance) {
this.accountBalance = accountBalance;
}

public String getOwnerName() {
return ownerName;
}

public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}

public double getInterestEarned() {
return interestEarned;
}

public void setInterestEarned(double interestEarned) {
this.interestEarned = interestEarned;
}
}