Question

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 a main function.

Both classes should have a default constructor and a custom constructor, as follows:

public Account() 
public Account(double initial)
public SavingsAccount()
public SavingsAccount(double inter)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code

============================================================================================

package sat;
//base class
class Account
{
   private double balance;

   public Account() {
       balance =0;
   }
   public Account(double balance) {
       this.balance = balance;
   }

   public double getBalance() {
       return balance;
   }

   public void deposit(double amount) {
       balance +=amount;
   }
  
}
//sub class
class SavingsAccount extends Account
{
   private double interest;
   public SavingsAccount()
   {
       interest=0;
   }
   public SavingsAccount(double inter)
   {
       interest=inter;
   }
   //add interest
   void addInterest(Account ob)
   {
       double t=ob.getBalance();
       t=t*interest/100;
       ob.deposit(t);
   }
  
}
public class AccountTest {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       Account a=new Account(1000);
       System.out.println("initial balance is "+a.getBalance());
      
       SavingsAccount ob=new SavingsAccount(8.1);
       ob.addInterest(a);
       System.out.println("new balance is "+a.getBalance());
      
      
   }

}

============================================================================================

Output

Java-sat/src/sat/Account lestiava-Eclipse Eile Edit Source Refattor Navigate Search Project Run岦indow Help 0 Access ava a Pac

Add a comment
Know the answer?
Add Answer to:
In C++: Define a class named Account that stores a balance (monetary amount). The class 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
  • 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...

  • 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,...

  • C++ Create a class named SavingsAccount that contains the following: Three (3) private class variables: a...

    C++ Create a class named SavingsAccount that contains the following: Three (3) private class variables: a String called ‘name’, a double called “balance” and another double called “interestRate” and 4 function prototypes. A constructor that receives 3 parameters: a string, and 2 doubles; the constructor will use these parameters to initialize the name, the balance, and the interestRate respectively. setBalance: it receives a double parameter called theBalance and assigns it to the balance. getBalance: it returns the balance. calculateInterestAmount: it...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify 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...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • ATM Revisited In Java, design a subclass of the Account class called GoldAccount. It is still...

    ATM Revisited In Java, design a subclass of the Account class called GoldAccount. It is still an Account class, however it has an additional field and some additional functionality. But it will still retain all the behavior of the Account class. Write a class called GoldAccount. This class will have an additional private field called bonusPoints. This field will require no get or set methods. But it will need to be initialized to 100 in the constructor. Thereafter, after a...

  • The Account class Create a class named Account, which has the following private properties: number: long...

    The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...

  • 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...

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

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