Question

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. Write an application to test class SavingsAccount.  Create three savingsAccount objects, saver1, saver2, and saver3 with balances of $2,000.00, $3,000.00, and 0.00, respectively.  Set annualInterestRate to 4%, then calculate the monthly interest and display the new balances for both savers.  Then set the annualInterestRate to 5%, calculate the next month’s interest and display the new balances for both savers.

Technical Requirements:

Create SavingsAccount class with static variable annualInterestRate and private instance variables savingsBalance (double) and savingsAccountName (string).

Create a mutator method to set the savingsAccountName.  Call this method setSavingsAccountName.  The method should take a string argument and return void.

Create an accessor method to retrieve the savingsAccountName.  Call this method getSavingsAccountName.  The method should take no arguments and return a string (i.e. the savingsAccountName).

Create a mutator method to set the savingsBalance.  Call this method setSavingsBalance.  The method should take a double argument and return void.  

Create an accessor method to retrieve the savingsBalance.  Call this method getSavingsBalance.  The method should take no arguments and return a double (i.e. the savingsBalance).

Include two constructors. The first takes no arguments and sets the savingsBalance variables to zero and sets the savingsAccountName to an empty string by calling the second (i.e. two argument) constructor with 0 and an empty string.  The second constructor takes one double argument (the savingsBalance) and one string argument (the savingsAccountName), and sets the savingsBalance by calling the setSavingsBalance method and setsavingsAccountName method, respectively.

Create CalculateMonthlyInterest method with formula.  The method should return void.

Create setAnnualInterestRate method to take a double argument representing the annualInterestRate and return void.

Create PrintSavingsAccount method to display the savingsBalance, savingsAccountName, and annualInterestRate for an object.  Use the output shown below as a guideline for the display.

Create a separate class called SavingsAccountTest, which contains the Main() method.

In the Main() method, create three savingsAccount objects called saver1,  saver2, and saver3.  Initialize saver1 and saver2 with the balances listed above and the names “Saver_One” and “Saver_Two”, respectively.  Do not initialize saver3 with anything.  Instead, create the object by invoking its zero-argument constructor, which will initialize its balance to 0 and its name to an empty string.

In the Main() method, call setAnnualInterestRate to set the interest rate to 4%.

Next, call the setSavingsAccountName for saver3 to set its name to “Saver_Three”.  Then, call the setSavingsAccountBalance for saver3 to set its balance to $50,000.

Print the results by calling PrintSavingsAccount for each object.

Next, call the CalculateAnnualInterestRate method for all three saver objects.

Print the results again by calling PrintSavingsAccount for each object.

Next, change the annualInterestRate to 5% by calling the setAnnualInterestRate method.

Print the results again by calling PrintSavingsAccount for each object.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

// SavingAccount class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
public class SavingAccount
{
// interest rate for all accounts
private static decimal annualInterestRate = 0;

private decimal savingsBalance; // balance for current account

// constructor, creates a new account with the specified balance
public SavingAccount(decimal balance)
{
savingsBalance = balance;
} // end constructor

// add the monthly interest to the balance
public void CalculateMonthlyInterest()
{
savingsBalance += savingsBalance * (annualInterestRate / 12.0M);
} // end method CalculateMonthlyInterest

// modify interest rate
public static void ModifyInterestRate(decimal newRate)
{
annualInterestRate =
(newRate >= 0 && newRate <= 1) ? newRate : 0.04M;
} // end method ModifyInterestRate

// get string representation of SavingAccount
public override string ToString()
{
return string.Format("{0:C}", savingsBalance);
} // end method ToString
} // end class SavingAccount

}



// Tests the SavingAccount class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
public class SavingAccountTest
{
public static void Main(string[] args)
{
SavingAccount saver1 = new SavingAccount(2000);
SavingAccount saver2 = new SavingAccount(3000);
SavingAccount.ModifyInterestRate(0.04M);

Console.WriteLine("Monthly balances for one year at .04");
Console.WriteLine("Balances:");

Console.WriteLine("{0,10}{1,10}{2,10}", "", "Saver 1", "Saver 2");
Console.WriteLine("{0,-10}{1,10}{2,10}", "Base",
saver1.ToString(), saver2.ToString());

for (int month = 1; month <= 12; month++)
{
string monthLabel = string.Format("Month {0}:", month);
saver1.CalculateMonthlyInterest();
saver2.CalculateMonthlyInterest();

Console.WriteLine("{0,-10}{1,10}{2,10}", monthLabel,
saver1.ToString(), saver2.ToString());
} // end for

}
}
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...
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
  • 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...

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

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

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

  • C++ implement and use the methods for a class called Seller that represents information about a...

    C++ implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; }; Data Members The...

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • I Need Help with this using Java Programming : Class name fname lname Class variable total...

    I Need Help with this using Java Programming : Class name fname lname Class variable total Number Constructor (no arguments) Constructor (takes two arguments, fname and lname) One getter method to return the fname and lname One setter method for fname and lname Inside Main: Create three objects with the following names Jill Doe John James Jack Smith When creating the first object (Should not be an anonymous object) use the argument-less constructor Then use the setter method to assign...

  • Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp....

    Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...

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

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

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