Question

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. Create two savings Account objects, saver1 andsaver2, with balances of $2000 and 3000. Set annualInterestRate to 4%, then calculate the monthly interest and display the new balances for both savers. Then set theannualInterestRate to 5%, calculate the next months interest and display the new balances for both savers.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

class SavingsAccount
{
public:
SavingsAccount(){}
SavingsAccount(int value);
~SavingsAccount(){}
static float annualInterestRate;
void calculateMonthlyInterest();
static void modifyIntererestRate(float value);
float GetBalance() const { return savingsBalance; }
private:
// Each member of the class contains a private data member
// savingsBalance indicating the amount the saver currently has
// on deposit.
float savingsBalance;
};

// copy constructor to initialize the value at instantiation
SavingsAccount::SavingsAccount(int value)
{
savingsBalance = value;
}

// Use a static data member annualInterestRate to store the annual interest
// rate for each of the savers.
float SavingsAccount::annualInterestRate = 0;

// Provide member function calculateMonthlyInterest that calculates the
// monthly interest by multiplying the savingsBalance by annualInterestRate
// divided by 12 and then adds this interest to savingsBalance.
void SavingsAccount::calculateMonthlyInterest()
{
savingsBalance += ((savingsBalance * annualInterestRate) / 12);
}

//Provide a static member function modifyIntererestRate that sets the
// static annualInterestRate to a new value.
void SavingsAccount::modifyIntererestRate(float value)
{
annualInterestRate = value;
}

int main()
{
// Instantiate two different objects of class SavingsAccount, saver1
// and saver2, with balances of $2000.00 and $3000.00, respectively.
SavingsAccount saver1(2000.00);
SavingsAccount saver2(3000.00);

// Set the annualInterestRate to 3%.
SavingsAccount::modifyIntererestRate(3);

// Then calculate the monthly interest and print the new balances for
// each of the savers.
saver1.calculateMonthlyInterest();
cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
saver2.calculateMonthlyInterest();
cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

cout << endl;

// Then set the annualInterestRate to 4%
SavingsAccount::modifyIntererestRate(4);

// and calculate the next month's interest and print the new balances
// for each of the savers
saver1.calculateMonthlyInterest();
cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
saver2.calculateMonthlyInterest();
cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

cout << endl;
return 0;
}
Add a comment
Know the answer?
Add Answer to:
C# How to Program: 10.5 Savings account class
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....

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

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

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

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

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

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

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

  • The code is attached below has the Account class that was designed to model a bank account.

    IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...

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

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