You are to create a menu-driven application that supports multiple bank accounts
ID: 3767171 • Letter: Y
Question
You are to create a menu-driven application that supports multiple bank accounts. You will need to implement functionality shown in the following menu:
***BANKING MENU***
1- Create a new checking account
2- Create a new savings account
3- Delete existing account
4- View a specific account
5- View all accounts
6- Write checks for a checking account 7- Deposit funds into an account
8- Withdraw funds from an account
9- Find account with the largest balance 10-Exit program
Enter option:
For option 1: Prompt the user for the initial balance and interest rate. Then call the method createChecking, passing the accounts ArrayList, balance, id, and interest rate.
For option 2: Prompt the user for the initial balance and interest rate. Then call the method createSavings, passing the accounts ArrayList, balance, id, and interest rate.
For option 3: Call the method deleteAccount, passing the accounts ArrayList. Call the method displayAccounts, which accepts the ArrayList accounts, to display all the existing accounts. When you return from the displayAccounts method, prompt the user to enter the id of the account to delete and process accordingly.
For option 4: Call the method displayAccount. In the method, display all accounts and ask the user for the id of the account they want to display. The method should determine the type of the account, display the type of the account, and display the account information for the specific account requested by the user. NOTE: If a checking account is being viewed, also open the checksfile for the account (each checking account should have its own checks file) and determine how many pending checks this account has. Then display the number of pending checks as well (see example below).
For option 5: Call the displayAccounts method and pass in the accounts ArrayList to display all the accounts. Before displaying each account, determine and display whether or not the account is a checking account or a savings account. Also display the number of pending checks for each checking account.
For option 6: Call the displayAccounts method and ask the user to enter a checking account to write a check for. Retrieve the account and call the createCheck method which will write a check for the account (see the writeCheck method of the CheckingAccount for details).
For option 7: Call the displayAccounts method and prompt the user for the deposit amount and the account id. Call the deposit method on the account object to update the balance.
For option 8: Call the displayAccounts method passing the accounts ArrayList. Prompt the user for the account id to make a withdrawal from. If withdrawing from a savings account, call the corresponding account’s withdraw method after you prompt for the amount to withdraw. If withdrawing from a checking account, call the account’s processChecks method.
For option 9: Call the findLargestBalance method, sending accounts ArrayList. Loop through the list and display the largest balance found.
For Option 10: Confirm the user wishes to end the program, and if so exit the program.
You will create a class named MustangBanking that contains your main method and the methods associated with each of the menu options. All accounts (checking and savings) will be added to a single ArrayList. The ArrayList resides in main method and is defined as follows:
ArrayList<Account> accounts = new ArrayList<>();
The Account class is to contain the following member data and methods:
A protected int data field named id for the account (default 0).
A protected double data field named balance for the account (default 0).
A protected double data field named annualInterestRate that stores the
current interest rate (default 0). Assume all accounts have the same
interest rate.
A protected Date data field named dateCreated that stores the date when
the account was created. You will need to research java.util.Date.
A 3-argument constructor that creates an account with the specified initial
balance, interest rate and id is passed in to it.
The accessors (get methods) and mutators (set methods) for id, balance,
and annualInterestRate.
The accessor (get method) for dateCreated.
A method named getMonthlyInterestRate that returns the monthly interest
rate.
A method named deposit that deposits a specified amount to the account.
A method named displayAccountInformation that displays the id, balance,
date created and annual interest rate for the account.
A method named largestAccount that compares two account objects and
returns the account object with the largest balance. Use this for the method header:
public Account largestAccount(Account acct)
The CheckingAccount class is to inherit from the Account class and contains the following member data and methods:
A 3-argument constructor that creates an account with the specified initial balance and interest rate passed in to it. The account id number is to be automatically generated by your program in such a way to guarantee that each id is unique.
A method named writeCheck that prompts the user for the amount of the check and writes the account id and the check amount to a text file called checks.txt (Hint: Each checking account will have its own checks file associated with it).
A method named processChecks that reads in checks which may be saved for this account and withdraws the check amount from the account balance.
A method called countPendingChecks that counts the number of checks in the account’s text file and returns the count.
The SavingsAccount class is to inherit from the Account class and contains the following member data and methods:
A 3-argument constructor that creates an account with the specified initial balance and interest rate passed into it. The account id number is to be automatically generated by your program in such a way to guarantee that each id is unique.
A method named withdraw withdraws the specified amount from the account.
Notes: Language is Java. This is what I have so far..
import java.util.*;
public class Account{
private int id;
private double balance ;
private double annualInterestRate;
private java.util.Date dateCreated;
public Account(){
dateCreated = new java.util.Date();
}
public Account(int newId, double newBalance, double newAnnualInterestRate){
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
dateCreated = new java.util.Date();
}
public int getID() {
return id;
}
public double getBalance(){
return balance;
}
public void setID(int newId) {
id = newId;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public void setAnnualInterestrate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public double getMonthlyInterestRate() {
return balance*(annualInterestRate);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
if( balance < amount)
{
System.out.println("Insufficent balance in the account");
}
else
{
this.balance -=amount;
System.out.println("Afterwithdrawing $"+ amount + " balance in account is: $" + balance);
}
}
public void deposit(double amount) {
balance += amount;
System.out.println(" Afterdepositing $" + amount + " balance in account is: $" + balance);
}
public void displayAccountInformation () {
System.out.println("The account number is: " + id);
System.out.println("The account balance is: $" + balance);
}
public void displayLargestBalance() {
System.out.println("The account number is: " + id);
System.out.println("The account balance is: $" + balance);
}
}
import java.util.*;
public class Lab7 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
displayMenu();
int choice = input.nextInt();
ArrayList<Account> accounts = new ArrayList<>();
int NumOfAccount = 0;
// while loop allows program to quit
while(choice != 9){
// creating switch statement
switch(choice){
// new values for balance through depositing and withdrawing
case 1:
double newBalance, newAnnualInterestRate;
System.out.println("Enter the initial balance for checking acount: ");
newBalance = input.nextDouble();
System.out.println("Enter the annual interest rate: ");
newAnnualInterestRate = input.nextDouble();
createChecking i = new createChecking(++NumOfAccount, newBalance, newAnnualInterestRate);
createChecking.add(i);
System.out.println("Your account number is: " + NumOfAccount);
displayMenu();
choice = input.nextInt();
break;
case 2:
double newBalance, newAnnualInterestRate;
System.out.println("Enter the initial balance for savings acount: ");
newBalance = input.nextDouble();
System.out.println("Enter the annual interest rate: ");
newAnnualInterestRate = input.nextDouble();
createSavings i = new createSavings(++NumOfAccount, newBalance, newAnnualInterestRate);
accounts.add(i);
System.out.println("Your account number is: " + NumOfAccount);
break;
case 3:
System.out.println("Enter the account number of the acccount you would like to delete: ");
int accDelete = input.nextInt() - 1;
accounts.remove(accDelete);
System.out.println("Account number: " + accDelete + " has been deleted");
displayMenu();
choice = input.nextInt();
break;
case 4:
System.out.println("Enter the account number of the account you would like to view: ");
int accView = input.nextInt();
int index = search(accounts, accView);
accounts.get(index).displayAccountInformation();
displayMenu();
choice = input.nextInt();
break;
case 4:
for (int j = 0; j < accounts.size(); j++){
accounts.get(j).displayAccountInformation();
}
displayMenu();
choice = input.nextInt();
break;
case 5:
System.out.println("Enter the account number of the account you would like to deposit from:");
int accNum = input.nextInt();
System.out.print("Enter amount to deposit: ");
double amount = input.nextDouble();
int index1 = search2(accounts, accNum);
accounts.get(index1).deposit(amount);
displayMenu();
choice = input.nextInt();
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
System.out.println("Enter the account number of the account you would like to withdraw from:");
int accNum2 = input.nextInt();
accNum2 = NumOfAccount;
System.out.println("Enter amount to withdraw: ");
double amountWithdraw = input.nextDouble();
int index2 = search3(accounts, accNum2);
accounts.get(index2).withdraw(amountWithdraw);
displayMenu();
choice = input.nextInt();
break;
case 9:
System.out.println("Which accounts would you like to compare? Enter first account number:");
int accNum3 = input.nextInt() - 1;
System.out.println("Enter the second account number:");
int accNum4 = input.nextInt() - 1;
if (accounts.get(accNum3).getBalance() > accounts.get(accNum4).getBalance()){
accounts.get(accNum3).displayLargestBalance();
}
else {
accounts.get(accNum4).displayLargestBalance();
}
displayMenu();
choice = input.nextInt();
break;
default: System.out.println("Invalid entry");
break;
}
}
}
public static void displayMenu(){
System.out.println("MUSTANG BANKING MENU");
System.out.println("1- Create a new checking account");
System.out.println("2- Create a new savings account");
System.out.println("3-Delete existing account.");
System.out.println("4-View a specific account.");
System.out.println("5-View all accounts");
System.out.println("6-Write checks for a checking account");
System.out.println("7- Deposit funds into an account")
System.out.println("8-Withdrawl funds from an account.");
System.out.println("9-Find account with the largest balance.");
System.out.println("10-Exit program.");
System.out.println("Enter option:");
}
public static int search(ArrayList<Account> accounts, int accView){
int searchValue = 0;
for (int i = 0; i < accounts.size(); i++){
if (accView == accounts.get(i).getID() ){
searchValue = i;
}
}
return searchValue;
}
public static int search2 (ArrayList<Account> accounts, int accNum){
int searchValue = 0;
for (int i = 0; i < accounts.size(); i++){
if (accNum == accounts.get(i).getID() ){
searchValue = i;
}
}
return searchValue;
}
public static int search3 (ArrayList<Account> accounts, int accNum2){
int searchValue = 0;
for (int i = 0; i < accounts.size(); i++){
if (accNum2 == accounts.get(i).getID() ){
searchValue = i;
}
}
return searchValue;
}
}
import java.util.*;
public class SavingsAcoount extends account {
public SavingsAcoount(){
super();
}
}
Explanation / Answer
import java.util.*;
import java.io.*;
import java.lang.*;
public class Account{
protected int id;
protected double balance ;
protected double annualInterestRate;
protected java.util.Date dateCreated;
public Account(){
dateCreated = new java.util.Date();
}
public Account(int newId, double newBalance, double newAnnualInterestRate){
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
dateCreated = new java.util.Date();
}
public int getID() {
return id;
}
public double getBalance(){
return balance;
}
public void setID(int newId) {
id = newId;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public void setAnnualInterestrate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public double getMonthlyInterestRate() {
return (annualInterestRate/12);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
if( balance < amount)
{
System.out.println("Insufficent balance in the account");
}
else
{
this.balance -=amount;
System.out.println("Afterwithdrawing $"+ amount + " balance in account is: $" + balance);
}
}
public void deposit(double amount) {
balance += amount;
System.out.println(" Afterdepositing $" + amount + " balance in account is: $" + balance);
}
public void displayAccountInformation () {
System.out.println("The account number is: " + id);
System.out.println("The account balance is: $" + balance);
System.out.println("Date created: " + dateCreated);
System.out.println("Annual Interset Rate" + annualInterestRate);
}
public Account largestAccount(Account acct) {
if(this.balance>acct.balance)
return this;
else
return acct;
}
}
public class CheckingAccount extends Account
{
public CheckingAccount(int id,double balance,double rate)
{
super(id,balance,rate);
}
public void writeCheck () throws IOException,FileNotFoundException
{
double checkAmount;
Scanner b=new Scanner(System.in);
FileWriter f1=new FileWriter("checks.txt");
BufferedWriter ab=new BufferedWriter(f1);
System.out.println("Enter the check amount:");
checkAmount =b.nextDouble();
ab.write(Integer.toString(super.getID()));
ab.append(" ");
ab.append(Double.toString(checkAmount));
ab.close();
}
public void processChecks () throws IOException,FileNotFoundException
{
FileReader f1=new FileReader("checks.txt");
BufferedReader ab=new BufferedReader(f1);
String in=ab.readLine();
if(in!=null&&!in.isEmpty())
{
String[] inf1=in.split(" ");
int accid=Integer.parseInt(inf1[0]);
double amt1=Double.parseDouble(inf1[1]);
super.withdraw(amt1);
}
}
}
public class SavingsAccount extends Account
{
public SavingsAccount(int id,double balance,double rate)
{
super(id,balance,rate);
}
public void withdraw(double amt)
{
super.withdraw(amt);
}
}
public class MustangBanking
{
public static void main(String[] args)
{
ArrayList<Account> accounts=new ArrayList<>();
Scanner bankInput=new Scanner(System.in);
int id;
double balance;
double rate;
int a;
do
{
displayMenu();
System.out.println("ENTER YOUR CHOICE:");
int c=bankInput.nextInt();
switch(c)
{
case 1:
System.out.println("ENTER ID ");
id=bankInput.nextInt();
System.out.println("ENTER BALANCE ");
balance=bankInput.nextDouble();
System.out.println("ENTER ID ");
rate=bankInput.nextDouble();
createChecking(accounts, id,balance,rate);
break;
case 2:
System.out.println("ENTER ID ");
id=bankInput.nextInt();
System.out.println("ENTER BALANCE ");
balance=bankInput.nextDouble();
System.out.println("ENTER ID ");
rate=bankInput.nextDouble();
createSavings(accounts, id, balance, rate);
break;
case 3:
deleteAccount(accounts);
break;
case 4:
displayAccount(accounts);
break;
case 5:
displayAccounts(accounts);
break;
case 6:
case 7:
case 8:
case 9:
case 10:
System.exit(0);
break;
}System.out.println("DO U WANT TO CONTINUE");
a=bankInput.nextInt();
}while(a==1);
}
public static void createChecking(ArrayList<Account>acct, int id,double balance,double rate)
{
CheckingAccount ck=new CheckingAccount(id,balance,rate);
acct.add(ck);
}
public static void createSavings(ArrayList<Account>acct, int id,double balance,double rate)
{
SavingsAccount sk=new SavingsAccount(id,balance,rate);
acct.add(sk);
}
public static void deleteAccount(ArrayList<Account>acct)
{
displayAccounts(acct);
Scanner sb=new Scanner(System.in);
System.out.println("ENTER THE ID TO DELETE ACCOUNT:");
int id=sb.nextInt();
for(Account act:acct)
{
if(act.getID()==id)
{
acct.remove(act);
}
}
}
public static void displayAccount(ArrayList<Account> acct)
{
displayAccount(acct);
Scanner sb=new Scanner(System.in);
System.out.println("ENTER THE ID TO PRINT ACCOUNT:");
int id=sb.nextInt();
for(Account act:acct)
{
if(act.getID()==id)
{
act.displayAccountInformation ();
}
}
}
public static void displayAccounts(ArrayList<Account> acct)
{
for(Account act:acct)
{
act.displayAccountInformation ();
}
}
public static void displayMenu(){
System.out.println("MUSTANG BANKING MENU");
System.out.println("1- Create a new checking account");
System.out.println("2- Create a new savings account");
System.out.println("3-Delete existing account.");
System.out.println("4-View a specific account.");
System.out.println("5-View all accounts");
System.out.println("6-Write checks for a checking account");
System.out.println("7- Deposit funds into an account");
System.out.println("8-Withdrawl funds from an account.");
System.out.println("9-Find account with the largest balance.");
System.out.println("10-Exit program.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.