Question

Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should...

Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should have an interest rate that is specified in its constructor. Furthermore, there should be a method, addInterest, that deposits interest into account, based on the account balance and interest rate.

Create another subclass of BankAccount named CheckingAccount. A CheckingAccount should keep track of the number of transactions made (deposits and withdrawals). Name this field transactionCount. Also, the set fee for transactions is three dollars, so create a static final field,
TRANSACTION_FEE, that is set to 3.0. Finally, create a method, deductFees, that deducts fees from the account balance based on the number of transactions. This method should reset the transactionCount to zero.

Now make a class BankAccountTest with a main method to test the above classes. Create a SavingsAccount with zero balance, a 1% interest rate, and a name of your choice. Also create a CheckingAccount with a $500 initial balance and a name of your choice. Deposit $1000 into the SavingsAccount. Withdraw $100 from the CheckingAccount. Now transfer $200 from the SavingsAccount to the CheckingAccount. Print out both accounts. Now add interest to theSavingsAccount and deduct fees from the CheckingAccount. Print out both accounts and make sure the balances are as expected.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*Test java progam for the SavingsAccount and CheckingAccount class.*/
//BankAccountTest.java
public class BankAccountTest
{
   public static void main(String[] args)
   {
       //create an instance of SavingsAccount class
       SavingsAccount savings=new SavingsAccount("SAVINGS", 0, 1);
       //call deposit method
       savings.deposit(500);
      
       //create an instance of CheckingAccount class
       CheckingAccount checkings=new CheckingAccount("CHECKINGS", 500);
       //call withdraw method
       checkings.withdraw(100);
      
       //call withdraw method on savings object
       savings.withdraw(200);
       //call deposit method on savings object
       checkings.deposit(200);
      
       savings.addInterest();
       checkings.deductFees();
      
       //print savings and checking account
       System.out.println("Savings Account");      
       System.out.println("Name: "+savings.getName());
       System.out.println("Balance,$: "+savings.getBalance());
      
       System.out.println("Checkings Account");      
       System.out.println("Name: "+checkings.getName());
       System.out.println("Balance,$: "+checkings.getBalance());
         
   }

}
----------------------------------------------------------------------------------------------------------------------------------------------------
//BankAccount.java
public class BankAccount
{
   private String name;
   private double balance;
  
   //constructor to set name and balance
   public BankAccount(String name, double balance) {
       this.name = name;
       this.balance = balance;
   }

   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
  
   public void deposit(double amt)
   {
       this.balance=this.balance+amt;
   }
  
   public void withdraw(double amt)
   {
       this.balance=this.balance-amt;
   }
  
  
   public double getBalance() {
       return balance;
   }
   public void setBalance(double balance) {
       this.balance = balance;
   }
  
}

----------------------------------------------------------------------------------------------------------------------------------------------------

//SavingsAccount.java
public class SavingsAccount extends BankAccount
{
   private double rate;
   public SavingsAccount(String name, double balance,
           double rate)
   {
       super(name, balance);
       this.rate=rate;
   }
  
   public void addInterest()
   {
       double bal=super.getBalance();
       double interest=super.getBalance()*(rate/100);
       setBalance(bal+interest);
   }
}
----------------------------------------------------------------------------------------------------------------------------------------------------

//CheckingAccount.java
public class CheckingAccount extends BankAccount
{
   //set transaction fee
   private static final double TRANSACTION_FEE=3.0;
   private double transactionCount;
  
   /*Constructor that takes name and baalance */
   public CheckingAccount(String name, double balance)
   {
       super(name, balance);
       transactionCount=0;
   }
   //Method that withdraw transaction fee
   //and reset the transaction count to zer0
   public void deductFees()
   {
       if(transactionCount>3)
       {
           super.withdraw(TRANSACTION_FEE);
           transactionCount=0;
       }
   }
  
   public void deposit(double amt)
   {
       super.deposit(amt);
       transactionCount++;
   }
   public void withdraw(double amt)
   {
       super.withdraw(amt);
       transactionCount++;
   }
  
}
----------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:

Savings Account
Name: SAVINGS
Balance,$: 303.0
Checkings Account
Name: CHECKINGS
Balance,$: 600.0

Add a comment
Know the answer?
Add Answer to:
Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to...

    JAVA Create a class called SavingsAccount. The class should have a static variable named, annualInterestRate, to store the annual interest rate for all account holders. Each object of the class should contain a private instance variable named, savingsBalance, indicating the amount the saver currently has on deposit. Write methods to perform the following: calculateMonthlyInterest – calculates the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12. This interest should be added to the balance. depositAmount – allows the...

  • BankAccount and SavingsAccount Classes (JAVA)

    Must be in GUI interfaceDesign an abstract class namedBankAccountto hold the following data for a bankaccount:* Balance* Number of deposits this month* Number of withdrawals (this month)* Annual interest rate* Monthly service chargesThe class should have the following methods:Constructor: The constructor should accept arguments for the balance and annual interest rate.deposit: A method that accepts an argument for the amount of the deposit. The methods should add the argument to the account balance. It should also increment thevariable holding the...

  • In C++: Define a class named Account that stores a balance (monetary amount). The class should...

    In C++: Define a class named Account that stores a balance (monetary amount). The class should have a private double variable balance. Add one accessor getBalance function that returns the balance and one deposit function that increases the balance by a given double amount. Then subclass Account with a SavingsAccount class. This class should have a private double variable interest. Add an addInterest function that increases the balance (from the superclass Account) according to the interest. Demonstrate the use in...

  • The program needs to be in python : First, create a BankAccount class. Your class should...

    The program needs to be in python : First, create a BankAccount class. Your class should support the following methods: class BankAccount (object): """Bank Account protected by a pin number.""" def (self, pin) : init "n"Initial account balance is 0 and pin is 'pin'."" self.balance - 0 self.pin pin def deposit (self, pin, amount): """Increment account balance by amount and return new balance.""" def withdraw (self, pin, amount): """Decrement account balance by amount and return amount withdrawn.""" def get balance...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT