Question: ***I will upvote as soon as I can*** Instructions: Given class BankAccount , define two subclasses according to comments in the code below. And then

***I will upvote as soon as I can***

Instructions:

Given class BankAccount, define two subclasses according to comments in the code below. And then write a driver program to test your subclasses try to use each method that you implemented at least once. Note: that there are two versions for several methods, a superclass one and a subclass one. Be careful about which one to use. /** An account that earns interest at a fixed rate. */

public class SavingsAccount extends BankAccount {

private double interestRate; /** Constructs a bank account with a given interest rate. @param rate the interest rate

*/ public SavingsAccount (double rate) {

} /** Calculate the interest and add it to the account balance. */

public void addInterest () { } } /** A checking account that charges transaction fees. */

public class CheckingAccount extends BankAccount { private static final int FREE_TRANSACTIONS = 3; private static final double TRANSACTION_FEE = 2.0; private int transactionCount; /** Constructs a checking account with a given balance. @param initialBalance the initial balance */

public CheckingAccount (double initialBalance) {

// call a superclass constructor to do // initialize the transaction count

} public void deposit (double amount) {

// increment the transaction count // add amount to balance

} public void withdraw (double amount) {

// increment the transaction count // subtract amount from balance

} /** Deducts the accumulated fees and resets the transaction count. */

public void deductFees () {

// check the transaction count and see if it is greater than

// FREE_TRANSACTIONS. If it is, calculate and deduct the fees

// from balance

// reset the transaction count

}

}

/** A bank account has a balance that can be changed by deposits and withdrawals. */ public class BankAccount { private double balance; /** Constructs a bank account with a zero balance. */ public BankAccount() { balance = 0; } /** Constructs a bank account with a given balance. @param initialBalance the initial balance */ public BankAccount(double initialBalance) { balance = initialBalance; } /** Deposits money into the bank account. @param amount the amount to deposit */ public void deposit(double amount) { balance = balance + amount; } /** Withdraws money from the bank account. @param amount the amount to withdraw */ public void withdraw(double amount) { balance = balance - amount; } /** Gets the current balance of the bank account. @return the current balance */ public double getBalance() { return balance; } /** Transfers money from the bank account to another account @param amount the amount to transfer @param other the other account */ public void transfer(double amount, BankAccount other) { withdraw(amount); other.deposit(amount); } }

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!