Question: Need to modify a java program that has the class BankAccount This program should have BankAccount class with the extensions of Checking, Savings, and Retirement
Need to modify a java program that has the class "BankAccount"
This program should have "BankAccount" class with the extensions of Checking, Savings, and Retirement classes.
OUTPUT OF PROGRAM:
This program should ask the user for their balance in their Checking, Savings, And Retirement accounts.
Once the user enters the amounts, the program should ask if the user wants to withdraw, deposit, or transfer money from a specific account.
When the user enters what they want to do(if transfer, have program ask from what account to what account), then the program should ask for what amount.
Once the user enters the amount, the program will display all 3 accounts with the adjusted balance.
HERE IS THE ORIGINAL CODE I NEED MODIFIED:
import java.util.Scanner;
public class BankAccount {
private double currentBal,previousBal;
private static char type;
public BankAccount(char type){
BankAccount.type = type;
}
public void deposit(double amount) {
previousBal = currentBal;
currentBal += amount;
}
public void withdraw(double amount) {
previousBal = currentBal;
currentBal -= amount;
}
public void transfer(BankAccount otherAccount,double amount){
otherAccount.deposit(amount);
this.withdraw(amount);
}
public double getCurrentBal(){
return currentBal;
}
public void setCurrentBal(double currentBal) {
this.currentBal = currentBal;
}
public double getPreviousBal() {
return previousBal;
}
public void setPreviousBal(double previousBal) {
this.previousBal = previousBal;}
public char getType() {
return type;
}
public void setType(char type) {
BankAccount.type = type;
}
public void bankFunctions(){
BankAccount savingsAcc = new BankAccount('S');
BankAccount checkingAcc = new BankAccount('C');
BankAccount retirementAcc = new BankAccount('R');
BankAccount[] accsArr = {savingsAcc,checkingAcc,retirementAcc};
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the balance of your Savings account: ");
savingsAcc.setCurrentBal(scanner.nextDouble());
System.out.println("Enter the balance of your Checking account: ");
checkingAcc.setCurrentBal(scanner.nextDouble());
System.out.println("Enter the balance of your Retirement account: ");
retirementAcc.setCurrentBal(scanner.nextDouble());
System.out.println("Please enter: 1 for Withdrawal 2 for Deposit 3 for Transfer");
int choice = scanner.nextInt();
int accChoice = 0;
double amount = 0;
switch(choice) {
case 1:
System.out.println("Please select account to withdraw from: 1 for "
+ "Savings Account 2 for Checking Account 3 for Retirement Account");
accChoice = scanner.nextInt();
System.out.println("Enter amount to withdraw: ");
amount = scanner.nextDouble();
accsArr[accChoice-1].withdraw(amount);
break;
case 2:
System.out.println("Please select account to deposit into: 1 for "
+ "Savings Account 2 for Checking Account 3 for Retirement Account");
accChoice = scanner.nextInt();
System.out.println("Enter amount to deposit: ");
amount = scanner.nextDouble();
accsArr[accChoice-1].deposit(amount);
break;
case 3:
System.out.println("Please select from which account to transfer: 1 for "
+ "Savings Account 2 for Checking Account 3 for Retirement Account");
accChoice = scanner.nextInt();
System.out.println("Please select to which account to transfer: 1 for "
+ "Savings Account 2 for Checking Account 3 for Retirement Account");
int secondChoice = scanner.nextInt();
System.out.println("Enter amount to transfer: ");
amount = scanner.nextDouble();
accsArr[accChoice-1].transfer(accsArr[secondChoice-1], amount);
break;
}
System.out.println("Savings Account: "+savingsAcc.getCurrentBal());
System.out.println("Checking Account: "+checkingAcc.getCurrentBal());
System.out.println("Retirement Account: "+retirementAcc.getCurrentBal());
scanner.close();
}
public static void main(String[] args) {
BankAccount myBankAccount = new BankAccount(type);
myBankAccount.bankFunctions();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
