Write a program named bank that maintains a database of bank accounts. Each acco
ID: 3631491 • Letter: W
Question
Write a program named bank that maintains a database of bank accounts. Each account will be stored in a BankAccount object. The Following example shows what the user will see:commands:
o - Open Account
d - Deposit
s - Select account
c - Close account
w - Withdraw
q - quit
Current Account: None selected
Enter command: o
Enter new account number: 123-456
Enter Initial balance: 100.00
commands:
o - Open Account
d - Deposit
s - Select account
c - Close account
w - Withdraw
q - quit
Current account:L 123-456 Balance: $100.00
Enter Command:
The program repeatedly promprs the user to enter commands, which it then exexutes. the program will not terminate until the user enters the command q. Note that the list f commands is redisplayed after each command has been executed, along with the current access and its balance. If there is not current account, the message "None Selected" is displayed instead of the account number.
Here are descriptions of the other commands:
Open account: The user is prompted t enter a new account number and intial balance. this data is stored in a new BankAccount object. BankAccount objects for all the existingaccounts must be stored in an array. the new account becomes the current account.
Close account: If there is no current account, the message
"Please select an account"
is displayed. Otherwise, the current account is removed from the array. There is no current account after this operation is completed.
Deposit: If there is no current account, the message " Please select an account" is displayed. Otherwise the user is promoted to enter the amount of the deposit: "Enter amount to deposit:". The amount entered by the user is added to the balance of the current account.
Withdraw: If there is no current account the message: "Please select an account" is displayed. Otherwise the user is promoted to enter the amount of the withdrawal "Enter amount to withdraw:". The amount entered by the user is subtracted to the balance of the current account.
Select account:The user is prompted to enter an account number: "Enter account number: " The array is then searched to see if any BankAccount object contains this number. If, so, that object becomes the current account. If Not, the following message is displayed: "Account number was not found."
Here are a few other requirements for the program:
-The array used to store Bank Account objects must contain only one element initially. When the array becomes full, it must be doubled in size.
-Dollae amount must be displayed correctly, with 2 digits after the decimal point. For example, make sure that your program displays $100.00 and not $100.0.
-All user input may be preceded or followed by spaces. commands may be entered as uppercase or lowercase letters. If the user enters a command other than o, c, d, w, s, or q, the program must display the following message:
"Command was not recognized; Please try again."
Explanation / Answer
import java.util.*; class BankAccount { static Scanner input = new Scanner(System.in); String name, actype; int accNo, bal, amt; BankAccount(String name, int accNo, String actype, int bal) { this.name = name; this.accNo = accNo; this.actype = actype; this.bal = bal; } int deposit() { System.out.print("Enter amount to deposit:"); amt = input.nextInt(); if (amt < 0) { System.out.println("Invalid Amount"); return 1; } bal = bal + amt; return 0; } int withdraw() { System.out.println("Your Balance=" + bal); System.out.print("Enter amount to withdraw:"); amt = input.nextInt(); if (balRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.