Question

a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus...


a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus rate for each of the savers (objects)

b) The class contains a private data member savingBalance indicating the amount the saver currently has on deposit.


c) Provide member function calculate MonthlyBonus that calculates the monthly bonus by multiplying the savingBalance by annualBonusRate divided by 12; this bonus should be addad to savingBalance.


d) Provide a static member function modifyBunusRate that has a parameter and use it to set the static annualBonusRate to a new value.


e) Write a driver program (containing main) to test class SavingsAccount, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively.

Set annualBonusRate to 3 percent only once

Then calculate the monthly bonus and print the new balance object , saver 1.

Will the annualBonusRatbe same for all objects? Explain the Answer.

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

As "annualBonusRate" is declared as static variable, value of "annualBonusRate" will be same for all objects....

Java Program:

class SavingsAccount
{
   static double annualBonusRate;
   private double savingBalance;
  
   //Constructor
   public SavingsAccount(double bal)
   {
       savingBalance = bal;
   }
  
   //Method that calculates monthly bonus
   public double MonthlyBonus()
   {
       return (savingBalance * (annualBonusRate)/12.0);
   }
  
   //Method that modified bonus rate
   public static void modifyBunusRate(double rate)
   {
       //Updating annualBonusRate
       annualBonusRate = rate;
   }
}

class SavingsAccountDriver
{
   //Main method
   public static void main(String args[])
   {
       //Creating objects
       SavingsAccount saver1 = new SavingsAccount(2000);
       SavingsAccount saver2 = new SavingsAccount(3000);
      
       //Set annualBonusRate to 3 percent
       SavingsAccount.modifyBunusRate(0.03);
      
       //Calculating monthly bonus
       System.out.println("Saver 1 Monthly Bonus: $" + (saver1.MonthlyBonus()));
       System.out.println("Saver 2 Monthly Bonus: $" + (saver2.MonthlyBonus()));
   }
}

___________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
a) Create saving account Class. Use a static data member annualBonusRate to store the annual bonus...
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
  • Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the...

    Create a .java file that has class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12- this interest should be added to savingsBalance. Provide a static method setInterestRate that sets the annualInterestRate to a new value....

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

  • C# How to Program: 10.5 Savings account class

    Create the class savings account. Use the static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the classcontains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate themonthly interest by multiplying the savingsBalance by annualInterestRate divided by 12, this interest should be added to savingsBlance, Provide static methodModifyInterestRate to set the annualInterestRate to a new value. Write an application to test class SavingsAccount....

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • Using C++ Please make sure you comment each section of the program so I can better...

    Using C++ Please make sure you comment each section of the program so I can better understand it. Thank you! Assignment Content You are now working for a bank, and one of your first projects consists of developing an application to manage savings accounts. Create a C++ program that does the following: Creates a SavingsAccount class Uses a static data member, annualInterestRate, to store the annual interest rate for each of the savers Ensures each member of the class contains...

  • Application should be in C# programming language Create a class called SavingsAccount.  ...

    Application should be in C# programming language Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the...

  • Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to...

    Define a class SavingsAccount with following characteristics. Use a static variable annualInterestRate of type float to store the annual interest rate for all account holders. Private data member savingsBalance of type float indicating the amount the saver currently has on deposit. Method calculateMonthlyInterest to calculate the monthly interest as (savingsBalance * annualInterestRate / 12). After calculation, the interest should be added to savingsBalance. Static method modifyInterestRate to set annualInterestRate. Parameterized constructor with savingsBalance as an argument to set the value...

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

  • In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,...

    In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

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