Question: Need to modify a java program that has the class BankAccount This is my 6th time posting this - no one know how to read

Need to modify a java program that has the class "BankAccount"

This is my 6th time posting this - no one know how to read directions.

USE THE PROGRAM I PASTED BELOW and extend BankAccount class to Checking, Savings, and Retirement. The new extended classes should have at least one private data attribute.

The new program should have the "BankAccount" class with the extensions of Checking, Savings, and Retirement classes.

Create a minimum of one private data attribute for your extended class. This can be a primitive variables (int, char, long, double etc..), or can be a reference variable (another class*).

Besides getter and setter methods, and at least one constructor in addition to the default, create at least one method that does something interesting with your class's data.

In your main method call the constructor(s) and method(s) of your class.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!