import java.util.Scanner; import java.util.ArrayList;
public class Banking {
public static void main(String[] args) { char option = ' '; System.out.println("Banking Application Team Member 1, Team Member 2, Team Member 3, ..."); ArrayList accounts = new ArrayList(); accounts.add(new CheckingAccount(3, 100.0)); accounts.add(new SavingsAccount(100.0, 2.5, 200.0)); accounts.add(new CDAccount(7.5, 60, 10000.00)); accounts.add(new SavingsAccount(100.0, 2.5, 300.0)); accounts.add(new CheckingAccount(3, 400.0)); accounts.add(new CDAccount(5.0, 2, 5000.00)); while (option != 'Q') { option = printMenu(); switch (option) { case 'D': makeDeposit(accounts); break; case 'W': makeWithdrawal(accounts); break; case 'M': doMonthEnd(accounts); break; case 'Q': break; default: System.out.println("Select D, W, M or Q"); } } }
public static char printMenu() { Scanner in = new Scanner(System.in); System.out.println(" D)eposit W)ithdraw M)onth end Q)uit"); return in.nextLine().toUpperCase().charAt(0); } public static void makeDeposit(ArrayListaccounts) { Scanner in = new Scanner(System.in); System.out.print("Account Number "); int acctNum = in.nextInt(); BankAccount targetAccount = accounts.get(acctNum); System.out.print("Amount "); double amount = in.nextDouble(); targetAccount.deposit(amount); System.out.printf("*** New balance: %.2f ", targetAccount.getBalance()); } public static void makeWithdrawal(ArrayListaccounts) { Scanner in = new Scanner(System.in); System.out.print("Account Number "); int acctNum = in.nextInt(); BankAccount targetAccount = accounts.get(acctNum); System.out.print("Amount "); double amount = in.nextDouble(); targetAccount.withdrawal(amount); System.out.printf("*** New balance: %.2f ", targetAccount.getBalance()); } public static void doMonthEnd(ArrayListaccounts) { for (int acct = 0; acct
1. Overview As a team, you are to complete several enhancements the Banking Application we went over in class: Add a new account type: Certificate of Deposit Add a List All function to the main menu Be sure to use inheritance to create the new account type and to make the Listing function very general. 2. Problem Description New Account Type Our client, ACME bank, will be offering a new Account Type: the Certificate of Deposit, also known simply as a CD. This new account behaves like any other Bank Account with the following exceptions: On creation: We must provide an interest rate, a term in months and an initial balance. Keep track of the number of months remaining until maturity (the term). Withdrawals before the term is up result in a penalty. On month end: Add interest to the account (rate x current balance). Reduce the number of remaining months in the term (but not to below 0). On withdrawal: Regardless of how much the account holder attempts to withdraw, a CD is an all-or-nothing account. Any attempt to take out money withdraws it all. If the account owner withdraws money before the CD matures, assess a 10% penalty. Print a message like this: Early CD Withdrawal. $1075.00 penalty, $9675.00 cashed out If the money is withdrawn after the CD matures, there is no penalty. Print a message like this: Mature CD Withdrawal. No penalty, $5512.50 cashed out Name the new class: CDAccount. New Application Functionality Our client would also like a nice list of all the active accounts. Add a new option to the User Menu: List All which is selected with an 'L'. When selected, the system will print details of each account. The information printed will be specific to each Account type. You are to do this by overriding and using the Object.toString() method. Output examples appear below: 0: Checking: Balance=$100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance=$200.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance=$10000.00, Term=60, Rate=0.075% Month end still prints short list as it always has. Application Design The design team has already reviewed the program requirements and developed the following UML diagram. The new/modified methods and classes are highlighted in blue. Banking +main(args[: String): void +printMenu(): char +makeDeposto): void +make Withdrawal(): void +do MonthEnd): void +ListAll(): void BankAccount -balance: double +BankAccount() +deposit(amount: double): void +withdrawal amount: double): void +monthEnd(): void +getBalance(): double +getMeasure(): double CDAccount CheckingAccount -maxWithdrawal: int -withdrawalCount: int +CheckingAccount(limit: int, initBal: double) +withdrawalamt: double): void +month End(): void +toString(): String SavingsAccount -rate: double -minBal: double Savings Account(double minBal, double rate, double initBal) +monthEnd(): void +toString(): String When your implementation is complete, be sure to run it with the test interactions shown below. Review the results to make sure that your application is working correctly. Notes You must start with the code found with this assignment: Banking.java - You will need to modify this file. However, do not change the test Accounts created. o BankAccount.java - You will not need to modify this file. o CheckingAccount.java - You will need to modify this file. o SavingsAccount.java - You will need to modify this file. Turn in all source files: CDAccount.java plus the four listed above. Make sure your classes are not in a package (that is, they are in the default package). Your output must include the names of all the team members. You must use inheritance for creating the class CDAccount. You must override and use Object.toString() for the List All functionality. You may want to investigate the method String.format(). It works like System.out.printf() but creates well-formatted String rather than producing output. Required Main Class Banking Required Input A series of menu selections, account numbers and amounts, as required by the operation. L 6. Required Output Your output should look like the following (User input is shown in GREEN). ACME Banking Application - Team Member 1, Team Member 2, Team Member 3, List All Deposit Withdraw Month end Quit 0: Checking: Balance $100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance=$200.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance=$10000.00, Term=60, Rate=0.075% 3: Savings: Balance $300.00, Minimum=$100.00, Rate=0.025% 4: Checking: Balance $400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance $5000.00, Term=2, Rate=0.050% List All Deposit Withdraw M)onth end Quit m 100.00 1: 205.00 2: 10750.00 3: 307.50 4: 400.00 5: 5250.00 : w List All Deposit Withdraw Month end Quit L 0: Checking: Balance $100.00, Allowed Withdrawals=3, #withdrawals=0 1: Savings: Balance-$295.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance $10750.00, Term=59, Rate=0.075% 3: Savings: Balance =$307.50, Minimum=$100.00, Rate=0.025% 4: Checking: Balance=$400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance $5250.00, Term=1, Rate=0.050% List All Deposit Withdraw Month end Quit Account Number 2 Amount 100 Early CD Withdrawal. $1075.00 penalty, $9675.00 cashed out *** New balance: 0.00 List All Deposit Withdraw Month end Quit 1 0: Checking: Balance $100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance-$205.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance $0.00, Term=59, Rate=0.075% 3: Savings: Balance-$307.50, Minimum=$100.00, Rate=0.025% 4: Checking: Balance-$400.00, Allowed Withdrawals-3, #Withdrawals=0 5: CD: Balance-$5250.00, Term-1, Rate=0.050% L)ist All Deposit Withdraw Month end Quit m @: 100.00 1: 210.13 2: 0.00 3: 315.19 4: 400.00 5: 5512.50 1 List All Deposit W)ithdraw Month end Quit 0: Checking: Balance =$100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance-$210.13, Minimum=$100.00, Rate=0.025% 2: CD: Balance $0.00, Term=58, Rate=0.075% 3: Savings: Balance-$315.19, Minimum=$100.00, Rate=0.025% 4: Checking: Balance=$400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance=$5512.50, Term=0, Rate=0.050% List All Deposit W)ithdraw Month end Quit Account Number 5 Amount 100 Mature CD Withdrawal. No penalty, $5512.50 cashed out *** New balance: 0.00 List All Deposit Withdraw Month end Quit W HO public class BankAccount implements Measureable { private double balance; public BankAccount() { balance = 0.0; } public BankAccount(double initBalance) { balance = initBalance; } public void deposit(double amt) { balance = balance + amt; } public void withdrawal (double amt) { balance = balance - amt; } public void monthEnd() { // Nothing to do. } public double getBalance() { return balance; } } public class CheckingAccount extends BankAccount { private int maxWithdraw; private int withdrawalCount; CheckingAccount(int withdrawlimit, double initialBalance) { maxWithdraw = withdrawLimit; withdrawalCount = 0; deposit(initialBalance); } public void withdrawal (double amt) { super.withdrawal (amt); withdrawalCount++; if (withdrawalCount > 3) { super.withdrawal(1.0); } } public void monthEnd() { withdrawalCount = 0; } } public class SavingsAccount extends BankAccount { private double rate; private double minimumBalance; Savings Account(double minimum, double rate, double initialBalance) { minimumBalance = minimum; this.rate = rate / 100.0; deposit(initialBalance); } public void monthEnd() { if (getBalance() >= minimumBalance) { deposit(rate * getBalance()); } * } } 1. Overview As a team, you are to complete several enhancements the Banking Application we went over in class: Add a new account type: Certificate of Deposit Add a List All function to the main menu Be sure to use inheritance to create the new account type and to make the Listing function very general. 2. Problem Description New Account Type Our client, ACME bank, will be offering a new Account Type: the Certificate of Deposit, also known simply as a CD. This new account behaves like any other Bank Account with the following exceptions: On creation: We must provide an interest rate, a term in months and an initial balance. Keep track of the number of months remaining until maturity (the term). Withdrawals before the term is up result in a penalty. On month end: Add interest to the account (rate x current balance). Reduce the number of remaining months in the term (but not to below 0). On withdrawal: Regardless of how much the account holder attempts to withdraw, a CD is an all-or-nothing account. Any attempt to take out money withdraws it all. If the account owner withdraws money before the CD matures, assess a 10% penalty. Print a message like this: Early CD Withdrawal. $1075.00 penalty, $9675.00 cashed out If the money is withdrawn after the CD matures, there is no penalty. Print a message like this: Mature CD Withdrawal. No penalty, $5512.50 cashed out Name the new class: CDAccount. New Application Functionality Our client would also like a nice list of all the active accounts. Add a new option to the User Menu: List All which is selected with an 'L'. When selected, the system will print details of each account. The information printed will be specific to each Account type. You are to do this by overriding and using the Object.toString() method. Output examples appear below: 0: Checking: Balance=$100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance=$200.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance=$10000.00, Term=60, Rate=0.075% Month end still prints short list as it always has. Application Design The design team has already reviewed the program requirements and developed the following UML diagram. The new/modified methods and classes are highlighted in blue. Banking +main(args[: String): void +printMenu(): char +makeDeposto): void +make Withdrawal(): void +do MonthEnd): void +ListAll(): void BankAccount -balance: double +BankAccount() +deposit(amount: double): void +withdrawal amount: double): void +monthEnd(): void +getBalance(): double +getMeasure(): double CDAccount CheckingAccount -maxWithdrawal: int -withdrawalCount: int +CheckingAccount(limit: int, initBal: double) +withdrawalamt: double): void +month End(): void +toString(): String SavingsAccount -rate: double -minBal: double Savings Account(double minBal, double rate, double initBal) +monthEnd(): void +toString(): String When your implementation is complete, be sure to run it with the test interactions shown below. Review the results to make sure that your application is working correctly. Notes You must start with the code found with this assignment: Banking.java - You will need to modify this file. However, do not change the test Accounts created. o BankAccount.java - You will not need to modify this file. o CheckingAccount.java - You will need to modify this file. o SavingsAccount.java - You will need to modify this file. Turn in all source files: CDAccount.java plus the four listed above. Make sure your classes are not in a package (that is, they are in the default package). Your output must include the names of all the team members. You must use inheritance for creating the class CDAccount. You must override and use Object.toString() for the List All functionality. You may want to investigate the method String.format(). It works like System.out.printf() but creates well-formatted String rather than producing output. Required Main Class Banking Required Input A series of menu selections, account numbers and amounts, as required by the operation. L 6. Required Output Your output should look like the following (User input is shown in GREEN). ACME Banking Application - Team Member 1, Team Member 2, Team Member 3, List All Deposit Withdraw Month end Quit 0: Checking: Balance $100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance=$200.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance=$10000.00, Term=60, Rate=0.075% 3: Savings: Balance $300.00, Minimum=$100.00, Rate=0.025% 4: Checking: Balance $400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance $5000.00, Term=2, Rate=0.050% List All Deposit Withdraw M)onth end Quit m 100.00 1: 205.00 2: 10750.00 3: 307.50 4: 400.00 5: 5250.00 : w List All Deposit Withdraw Month end Quit L 0: Checking: Balance $100.00, Allowed Withdrawals=3, #withdrawals=0 1: Savings: Balance-$295.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance $10750.00, Term=59, Rate=0.075% 3: Savings: Balance =$307.50, Minimum=$100.00, Rate=0.025% 4: Checking: Balance=$400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance $5250.00, Term=1, Rate=0.050% List All Deposit Withdraw Month end Quit Account Number 2 Amount 100 Early CD Withdrawal. $1075.00 penalty, $9675.00 cashed out *** New balance: 0.00 List All Deposit Withdraw Month end Quit 1 0: Checking: Balance $100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance-$205.00, Minimum=$100.00, Rate=0.025% 2: CD: Balance $0.00, Term=59, Rate=0.075% 3: Savings: Balance-$307.50, Minimum=$100.00, Rate=0.025% 4: Checking: Balance-$400.00, Allowed Withdrawals-3, #Withdrawals=0 5: CD: Balance-$5250.00, Term-1, Rate=0.050% L)ist All Deposit Withdraw Month end Quit m @: 100.00 1: 210.13 2: 0.00 3: 315.19 4: 400.00 5: 5512.50 1 List All Deposit W)ithdraw Month end Quit 0: Checking: Balance =$100.00, Allowed Withdrawals=3, #Withdrawals=0 1: Savings: Balance-$210.13, Minimum=$100.00, Rate=0.025% 2: CD: Balance $0.00, Term=58, Rate=0.075% 3: Savings: Balance-$315.19, Minimum=$100.00, Rate=0.025% 4: Checking: Balance=$400.00, Allowed Withdrawals=3, #Withdrawals=0 5: CD: Balance=$5512.50, Term=0, Rate=0.050% List All Deposit W)ithdraw Month end Quit Account Number 5 Amount 100 Mature CD Withdrawal. No penalty, $5512.50 cashed out *** New balance: 0.00 List All Deposit Withdraw Month end Quit W HO public class BankAccount implements Measureable { private double balance; public BankAccount() { balance = 0.0; } public BankAccount(double initBalance) { balance = initBalance; } public void deposit(double amt) { balance = balance + amt; } public void withdrawal (double amt) { balance = balance - amt; } public void monthEnd() { // Nothing to do. } public double getBalance() { return balance; } } public class CheckingAccount extends BankAccount { private int maxWithdraw; private int withdrawalCount; CheckingAccount(int withdrawlimit, double initialBalance) { maxWithdraw = withdrawLimit; withdrawalCount = 0; deposit(initialBalance); } public void withdrawal (double amt) { super.withdrawal (amt); withdrawalCount++; if (withdrawalCount > 3) { super.withdrawal(1.0); } } public void monthEnd() { withdrawalCount = 0; } } public class SavingsAccount extends BankAccount { private double rate; private double minimumBalance; Savings Account(double minimum, double rate, double initialBalance) { minimumBalance = minimum; this.rate = rate / 100.0; deposit(initialBalance); } public void monthEnd() { if (getBalance() >= minimumBalance) { deposit(rate * getBalance()); } * } }