Question
*JAVA CODE* does not need an account number or anything. This a general ATM program. take the following code (Bank Account class) and extend the
*JAVA CODE*
does not need an account number or anything. This a general ATM program.
take the following code (Bank Account class) and extend the class to Checking, Savings, and Retirement instead of it all being in the main class.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started