Write a program to simulate a bank which includes the following. Include a comme
ID: 3798655 • Letter: W
Question
Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program.
Create the following classes: (at least 3 classes total)
Bank
Customer
Account
At a minimum include the following data fields for each class:Bank
Routing number
Customer
First name
Last name
Account (Note that the Customer class contains the Account class as one of its data members.)
Account
Account number
Balance
Minimum balance
Overdraft fee
At a minimum write the following methods for each class:
Bank
(public static void main(String[] args) ; The Bank class will contain the main method.
Create new customer
Find Customer (Given an account number or customer name, retrieve the related customer and account.)
The bank must be able to contain multiple customers and multiple accounts. (This generally means the Bank class should include an array or Array List of Customer class objects.) The bank should be able to look up each customer by name and / or account number when performing transactions, such as withdrawals, deposits and balance inquiries.
Customer
OpenAccount
CloseAccount
GetAccount
Account
GetBalance
DepositFunds
WithdrawFunds
PrintAccountInfo
For added functionality, you may choose to create a base class of “Account” which you extend into derived classes checking and savings account classes.
In your main method within the Bank class, you may perform the bank operations using user input, or you may code the operations directly within your main method in the Bank class. For example, your program may contain a user menu with options such as withdraw, deposit, find customer, etc. Or you may simply hard code the operations directly in your main method such as create customer 1, deposit $100, withdraw $50, etc.
Explanation / Answer
import java.util.Scanner; public class Bankinfo { public static void main(String[] args) { Scanner s = new Scanner(System.in); Bank myBank = new Bank(); int user_choice = 2; do { System.out.println(); System.out.println("1) new account"); System.out.println("2) Deposit"); System.out.println("3) Withdraw"); System.out.println("4) Print balance"); System.out.println("5) Quit"); System.out.println(); System.out.print("Enter choice: "); user_choice = s.nextInt(); switch (user_choice) { case 1: System.out.println("Enter a customer name"); String cn = s.next(); System.out.println("Enter a opening balance"); double d = s.nextDouble(); System.out.println("Account was created and it's number: " + myBank.openNewAccount(cn, d)); break; case 2: System.out.println("Enter a account number"); int an = s.nextInt(); System.out.println("Enter a deposit amount"); double da = s.nextDouble(); myBank.depositTo(an, da); break; case 3: System.out.println("Enter a account number"); int acn = s.nextInt(); System.out.println("Enter a withdraw amount"); double wa = s.nextDouble(); myBank.withdrawFrom(acn, wa); break; case 4: System.out.println("Enter a account number"); int anum = s.nextInt(); myBank.printAccountInfo(anum); break; case 5: System.out.println("Here are the balances " + "for each account:"); case 6: System.exit(0); } } while (user_choice != '6'); } static class Bank { private BankAccount[] accounts; private int numOfAccounts = 5; public Bank() { accounts = new BankAccount[5]; numOfAccounts = 0; } public int openNewAccount(String customerName, double openingBalance) { BankAccount b = new BankAccount(customerName, openingBalance); accounts[numOfAccounts] = b; numOfAccounts++; return b.getAccountNum(); } public void withdrawFrom(int accountNum, double amount) { for (int i =0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.