I need help with this My first code kind of works but it isn

I need help with this. My first code kind of works, but it isn\'t showing the balance after each transaction. I\'m not getting any of this working correctly.

Develop a banking program using an Account class. Create SavingsAccount and CheckingAccount objects. For each account, the user to use an amount of money to withdraw from the account using member function, debit, and an amount of money to deposit into the account using member function, credit. As you process each account, determine its type. If an Account is aSavingsAccount, calculate the amount of interest owed to the account using member function, calculateInterest, then add the interest to the account balance using member function, credit. After processing an account, print the updated account balance obtained by invoking base-class member function, getBalance. If an Account is aCheckingAccount, calculate the fees (2%) charged per transaction.

The Account Inheritance Hierarchy is as follows:

Create a base class Account and derived classes, SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include one data member of type double to represent the account balance. The class should provide at least three member functions:

Member function, credit, should add an amount to the current balance.

Member function, debit, should withdraw money from the account and ensure the debit amount does not exceed the account’s balance. If it does, the balance should be left unchanged and the function should print the message “Debit amount exceeded account balance.”

Member function, getBalance, should return the current balance.

The SavingsAccount should have a data member of type double indicating the interest rate assigned to the account. It also includes a member function, calculateInterest, that returns a double indicating the amount of interest earned by an account, by multiplying the interest rate by the account balance.

The CheckingAccount should have a data member of type constant double indicating the fee charged per transaction. Every time there is a debit or a credit, it should subtract the fee from the account balance.CheckingAccount’s debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance.)

Use constructors to initialize the data members and make sure the initial balance is greater than or equal to zero.

Write a program to test your classes designed above by using the following numbers and transactions:

-500.00


(Yes, the last deposit into savings is a negative amount).

Make sure you display the balance after each transaction.

If there is an error, make sure you state the error and what caused it.

Turn in your code and your output file with the transactions above showing deposits and withdraws including all error messages.

Checking Starting Balance 500.00
Savings Starting Balance 1000.00
Withdraw from Checking 230.00
Withdraw from Savings 100.85
Deposit into Checking 400.25
Deposit into Checking 250.00
Deposit into Savings 500.00
Withdraw from Checking 2000.00
Withdraw from Savings 1000.00
Withdraw from Savings 1500.00
Deposit into Savings

-500.00

Solution

public class Account {
   private double balance;

   public Account(double balance) {

       this.balance = balance;
   }

   public void credit(double amount) {
       if (amount >= 0)
           balance += amount;
       else
           return;
   }

   public void debit(double amount) {

       if (balance >= amount) {
           balance -= amount;

       } else {

       }
   }

   public double getBalance() {

       return this.balance;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"Account [balance=\" + balance + \"]\";
   }

}
public class SavingsAccount extends Account {

   private double interestRate;

   public SavingsAccount(double balance, double interestRate) {
       super(balance);
       // TODO Auto-generated constructor stub
       this.interestRate = interestRate;
   }

   public double calculateInterest() {

       return interestRate * getBalance();
   }

}
public class CheckingAccount extends Account {

   private final double feeCharged = 20;

   public CheckingAccount(double balance) {
       super(balance);
       // TODO Auto-generated constructor stub
   }

   public void credit(double amount) {

       super.credit(amount);
       super.debit(feeCharged);
   }

   public void debit(double amount) {

       super.debit(feeCharged + amount);
   }

}
public class TestAccount {
   public static void main(String[] args) {

       CheckingAccount checkingAccount = new CheckingAccount(500);
       SavingsAccount savingsAccount = new SavingsAccount(1000, 0.10);

       System.out.println(\"Intial Checking Acc:\" + checkingAccount);
       System.out.println(\"Intial Savings Acc:\" + savingsAccount);

       checkingAccount.debit(230);
       savingsAccount.debit(100.85);
       System.out.println(\"After Debit Checking Acc:\" + checkingAccount);
       System.out.println(\"After Debit Savings Acc:\" + savingsAccount);

       checkingAccount.credit(400.25);
       checkingAccount.credit(250.00);

       System.out.println(\"After Credit Checking Acc:\" + checkingAccount);

       savingsAccount.credit(500.00);

       System.out.println(\"After Credit Savings Acc:\" + savingsAccount);

       checkingAccount.debit(2000);
       savingsAccount.debit(1000);
       System.out.println(\"After Debit Checking Acc:\" + checkingAccount);
       System.out.println(\"After Debit Savings Acc:\" + savingsAccount);

       savingsAccount.debit(1500);
       System.out.println(\"After Debit Savings Acc:\" + savingsAccount);

       savingsAccount.credit(-500);
       System.out.println(\"After credit Savings Acc:\" + savingsAccount);

   }
}
OUTPUT:
Intial Checking Acc:Account [balance=500.0]
Intial Savings Acc:Account [balance=1000.0]
After Debit Checking Acc:Account [balance=250.0]
After Debit Savings Acc:Account [balance=899.15]
After Credit Checking Acc:Account [balance=860.25]
After Credit Savings Acc:Account [balance=1399.15]
After Debit Checking Acc:Account [balance=860.25]
After Debit Savings Acc:Account [balance=399.1500000000001]
After Debit Savings Acc:Account [balance=399.1500000000001]
After credit Savings Acc:Account [balance=399.1500000000001]

I need help with this. My first code kind of works, but it isn\'t showing the balance after each transaction. I\'m not getting any of this working correctly. De
I need help with this. My first code kind of works, but it isn\'t showing the balance after each transaction. I\'m not getting any of this working correctly. De
I need help with this. My first code kind of works, but it isn\'t showing the balance after each transaction. I\'m not getting any of this working correctly. De
I need help with this. My first code kind of works, but it isn\'t showing the balance after each transaction. I\'m not getting any of this working correctly. De

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site