Question

The InterestBearingAccount interface declares a single method addInterest(no parameters, void return type) that increases the balance...

  • The InterestBearingAccount interface declares a single method addInterest(no parameters, void return type) that increases the balance by the interest rate that is appropriate for the particular account.
  • An InterestCheckingAccount is an Account that is also an InterestBearingAccount. Invoking addInterest increases the balance by 3%.
  • A PlatinumCheckingAccount is an InterestCheckingAccount. Invoking addInterest increases the balance by double the rate for an InterestCheckingAccount (whatever that rate happens to be).
  • A NonInterestCheckingAccount is an Account but it is not an InterestBearingAccount. It has no additional functionality beyond the basic Account class.

Hi, this program is in Java language. I have the Account class mostly done (there are some error messages). The Account class that those two classes are referring to is an abstract class. Furthermore, I believe the InterestBearingAccount (which is an interface) is being implemented by the Account class.

For the InterestBearingAccount interface, I currently have it as: return balance + (currentBalance * 3.00); but it is showing an error.

I believe for the NonInterestBearingAccount, there is nothing that needed to be added to it?

Will you be able to show me how you would implement these four classes?

Thank you.

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

Note: The question didn't ask for account class so I haven't created one instead I have fulfilled the instruction with only three classes

Program

interface InterestBearingAccount {//Interface for interest-bearing
   public void addInterest();
}

class InterestCheckingAccount implements InterestBearingAccount {
   private String name;
   private int accNumber;
   private double balance;
   private double interestRate;

   public InterestCheckingAccount(String name, int accNumber, double balance, double interestRate) {
       this.name = name;
       this.accNumber = accNumber;
       this.balance = balance;
       this.interestRate = interestRate;
   }

   public double getBalance() {
       return balance;
   }

   public double getInterestRate() {
       return interestRate;
   }

   @Override
   public void addInterest() {//calculating interest
       balance += balance * (interestRate / 100);
   }

   @Override
   public String toString() {//for showing account details
       return "Name= " + name + ", Account Number= " + accNumber;
   }
}

class PlatinumCheckingAccount implements InterestBearingAccount {

   private String name;
   private int accNumber;
   private double balance;
   private double interestRate;

   public PlatinumCheckingAccount(String name, int accNumber, double balance, double interestRate) {
       this.name = name;
       this.accNumber = accNumber;
       this.balance = balance;
       this.interestRate = interestRate*2;//doubling the checking account interest rate
   }

   public double getBalance() {
       return balance;
   }

   @Override
   public void addInterest() {
       balance += balance * (interestRate / 100);
   }

   @Override
   public String toString() {
       return "Name= " + name + ", Account Number= " + accNumber;
   }
}

class NonInterestCheckingAccount {//simple account
   private String name;
   private int accNumber;
   private double balance;

   public NonInterestCheckingAccount(String name, int accNumber, double balance) {
       this.name = name;
       this.accNumber = accNumber;
       this.balance = balance;
   }

   public double getBalance() {
       return balance;
   }

   @Override
   public String toString() {
       return "Name= " + name + ", Account Number= " + accNumber;
   }
}

public class Test {// driver class
   public static void main(String[] args) {
      
       InterestCheckingAccount obj = new InterestCheckingAccount("Daniel", 123, 1250.36, 3);//3% rate
       //sending checking account interest rate
       PlatinumCheckingAccount obj2 = new PlatinumCheckingAccount("Samantha", 124, 5236, obj.getInterestRate());
       NonInterestCheckingAccount obj3 = new NonInterestCheckingAccount("John", 125, 9650);
      
       //showing results
       System.out.println("******Checking Account******");
       System.out.println(obj);
       System.out.println("Balance before interest: "+obj.getBalance());
       obj.addInterest();
       System.out.println("Balance after interest: "+obj.getBalance());
       System.out.println("------------------------------");
      
       System.out.println("******Platinum Checking Account******");
       System.out.println(obj2);
       System.out.println("Balance before interest: "+obj2.getBalance());
       obj2.addInterest();
       System.out.println("Balance after interest: "+obj2.getBalance());
       System.out.println("------------------------------");
      
       System.out.println("******Non Interest Checking Account******");
       System.out.println(obj3);
       System.out.println("Balance: "+obj3.getBalance());
       System.out.println("------------------------------");
   }
}

Output

Add a comment
Know the answer?
Add Answer to:
The InterestBearingAccount interface declares a single method addInterest(no parameters, void return type) that increases the balance...
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
  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • I need help with the Implementation of an Ordered List (Template Files) public interface Ordered...

    I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...

  • c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one...

    c++ help please. Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance but has a higher interest rate (the benefit here being larger growth in this type of account). Checking accounts: Suppose that the bank offers three types of checking accounts: one with a monthly service charge, limited check writing, no minimum balance, and no interest; another with no...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • In this lab, a piece of working software is given. You are asked to make changes...

    In this lab, a piece of working software is given. You are asked to make changes to the software according to some requirement. The scenario in this lab mimics the situation that most old software applications are facing---need to update. When covering inheritance and polymorphism, we introduced a pattern that has three elements: instanceof operator, base pointers, and a collection data structure. In the given code, the collection used is a dynamic array (will change its length automatically) called Vector....

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
ADVERTISEMENT