Description of the problem: make a program that tests the implementation of all the classes. Before doing transaction, user should be prompted the type of his bank account: Savings or Checking. This is in a form of menu. After indicating the account type, user should be prompted to select transaction from a menu: deposit, withdraw, Inquire, or transfer. To check the implementation of addPeriodicInterest in Savings account, add the method MonthEnd() in your program. This method should be called so that interest be added to the balance of this saving account at the end of the month. Design your program such that all methods in both child class and parent class are tested. To make your program more realistic, your program should allow user do transactions until no more transactions needed. Use a loop statement for this process.
Description of the problem: make a program that tests the implementation of all the classes. Before doing transaction, user should be prompted the type of his bank account: Savings or Checking. This is in a form of menu. After indicating the account type, user should be prompted to select transaction from a menu: deposit, withdraw, Inquire, or transfer. To check the implementation of addPeriodicInterest in Savings account, add the method MonthEnd() in your program. This method should be called so that interest be added to the balance of this saving account at the end of the month. Design your program such that all methods in both child class and parent class are tested.
To make your program more realistic, your program should allow user do transactions until no more transactions needed. Use a loop statement for this process.
Below is initial code. Try to improve it and complete it with the Main program that satisfy the description of the problem. Also try to fix the redlines
No sample output because my initial code has some errors and I don't know how to fix them, but based on the description of the problem, it should display simple bank account that implements all the methods and classes.
public class BankAccount {
private double balance;
public BankAccount(double initialAmount) {
balance = initialAmount;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
balance -= amount;
}
public double getBalance() {
return balance;
}
public void transfer(BankAccount Other, double amount) {
withdraw(amount);
other.deposit(amount);
}
}
public class SavingsAccount extends BankAccount {
private double interestRate;
public SavingsAccount(double rate) {
interestRate = rate;
}
public SavingsAccount(double rate, double initialAmount) {
super(initialAmount);
interestRate = rate;
}
public void addPeriodicInterest() {
double interest = getBalance() * interestRate / 100.0;
deposit(interest);
}
}
public class CheckingAccount extends BankAccount {
private static final int FREE_TRANSACTIONS = 3;
private static final double TRANSACTION_FEE = 0.50;
private int transactionCount;
public CheckingAccount() {
transactionCount = 0;
}
public CheckingAccount(double initialAmount) {
super(initialAmount);
transactionCount = 0;
}
public void withdraw (double amount) {
super.withdraw(amount);
transactionCount++;
}
public void deposit(double amount) {
super.deposit(amount);
transactionCount++;
}
public void deductfees() {
if (transactionCount > FREE_TRANSACTIONS) {
double fee = TRANSACTION_FEE * (transactionCount - FREE_TRANSACTIONS);
super.withdraw(fee);
}
transactionCount = 0;
}
public static void main(String[] args) {
//put your code here
}
}
Step by step
Solved in 3 steps