From 49f0186ff684a0fc402c09c4a846f423b912e3f9 Mon Sep 17 00:00:00 2001 From: harsh183 Date: Tue, 2 Oct 2018 16:14:17 -0500 Subject: [PATCH 1/2] Finish bank account --- src/main/java/Bank.java | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/main/java/Bank.java b/src/main/java/Bank.java index f5b8592..985a929 100644 --- a/src/main/java/Bank.java +++ b/src/main/java/Bank.java @@ -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"; } @@ -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; } /** @@ -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; } /** @@ -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)); } /** @@ -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. @@ -89,6 +113,7 @@ public static int getNumberOfAccount() { /* * Implement this function */ + return totalAccounts; } /** @@ -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 "); From e5eaef4a9e5ba39e7614d3fdea274d5cff023b02 Mon Sep 17 00:00:00 2001 From: harsh183 Date: Tue, 2 Oct 2018 16:14:49 -0500 Subject: [PATCH 2/2] Create bank account --- src/main/java/BankAccount.java | 100 +++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 5 deletions(-) diff --git a/src/main/java/BankAccount.java b/src/main/java/BankAccount.java index 9d11a01..3354672 100644 --- a/src/main/java/BankAccount.java +++ b/src/main/java/BankAccount.java @@ -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; + } }