Question

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 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.-DK file:///C/209 C#Programming/Programming Assignments/Module 4/Assignment-4-Solution/Assignment-... Initial savings account

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

Done. I have added comments everywhere but still if you get any doubt please leave a comment I will get back to you. Output screenshot is also included.

///////////////////////////////////////SavingAccount.cs/////////////////////////////////////////////////////////

using System;

namespace AccountsApp
{

    public class SavingsAccount
    {
        //Annual interest rate for all account holders
        private static double annualInterestRate;
        // the amount the saver currently has on deposit
        private double savingsBalance;
        private string accountName;
        
        //constructor with no args. It sets balance and account name to initial values
        public SavingsAccount()
        {
            this.savingsBalance=0;
            this.accountName="";
        }
        
        //The second constructor takes one double argument (the savingsBalance) and one string argument
        public SavingsAccount(double balance, string acctName){
            setSavingsAccountBalance(balance);
            setSavingsAccountName(acctName);
        }
        //sets account name to passed values
        public void setSavingsAccountName (string name){
            this.accountName=name;
        }
        //returns account name
        public string getSavingAccountName(){
            return this.accountName;
        }
        //sets account balance
        public void setSavingsAccountBalance(double bal){
            this.savingsBalance=bal;
        }
        //calculate the monthly interest
        public void CalculateMonthlyInterest(){
            double monthelyInterest = annualInterestRate/12;
            double interest =    this.savingsBalance*monthelyInterest;
            double balance = getSavingAccountBalance()+interest;
            setSavingsAccountBalance(balance);
        }
        //sets annual interest rate
        public static void setAnnualInterestRate(double iRate){
            annualInterestRate=iRate;
        }
        //return saving balamce
        public double getSavingAccountBalance(){
            return this.savingsBalance;
        }
        //return annual interest
        public double getAnnualIntereset(){
            return annualInterestRate;
        }
        //prints all the values
        public void PrintSavingsAccount (){
            Console.WriteLine("{0,-20} {1,5}{2,15}", getSavingAccountName(), getSavingAccountBalance(),getAnnualIntereset());
        }
    }
}

/////////////////////////////////////////////End SavingAccount.cs//////////////////////////////////

////////////////////////////////////////////////////TestSavingAccounts.cs/////////////////////////////////////////////

using System;

namespace AccountsApp
{
    class Program
    {
        public static void Main(string[] args)
        {
            
            SavingsAccount saver1 = new SavingsAccount(4000.0, "Saver_One");
            SavingsAccount saver2 = new SavingsAccount(5000.0, "Saver_Two");
            //not initialize saver3 with anything. Only Zero arg constructor to be used
            SavingsAccount saver3 = new SavingsAccount();
            
            //setAnnualInterestRate to set the interest rate to 4%
            SavingsAccount.setAnnualInterestRate(0.04);
            //setSavingsAccountName for saver3 to set its name to “Saver_Three”
            saver3.setSavingsAccountName("Saver_Three");
            // set its balance to $50,000
            saver3.setSavingsAccountBalance(50000.0);
            
            Console.WriteLine("Initial Saving account balances:");
            //Print the results by calling PrintSavingsAccount for each object.
            saver1.PrintSavingsAccount();
            saver2.PrintSavingsAccount();
            saver3.PrintSavingsAccount();
            
            //call CalculateMonthlyInterest on each object
            saver1.CalculateMonthlyInterest();
            saver2.CalculateMonthlyInterest();
            saver3.CalculateMonthlyInterest();
            
            Console.WriteLine("Saving account balance after calculating monthly interest at 4% :");
            //Print the results by calling PrintSavingsAccount for each object.
            saver1.PrintSavingsAccount();
            saver2.PrintSavingsAccount();
            saver3.PrintSavingsAccount();
            //set the annualInterestRate to 5%
            SavingsAccount.setAnnualInterestRate(0.05);
            Console.WriteLine("Saving account balance after calculating monthly interest at 5% :");
            //Print the results by calling PrintSavingsAccount for each object.
            saver1.PrintSavingsAccount();
            saver1.PrintSavingsAccount();
            saver2.PrintSavingsAccount();
            saver3.PrintSavingsAccount();
            
            Console.Write("Press any key to continue . . . ");
            Console.ReadLine();
        }
    }
}

///////////////////////////////////////////END////////////////////////////////////////

Output Screenshot

AccountsApp-SharpDevelop File Initial Saving account balances: Saver One 9.04 9.04 0.04 aver TwO aver_Three aving account bal

Add a comment
Know the answer?
Add Answer to:
Application should be in C# programming language Create a class called SavingsAccount.  ...
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
  • 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....

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

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

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

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

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

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

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

  • How do you write a test class that tests each of the setters and constructors to ensure that the appropriate exception is raised?(Note: sed. Recall that the setter method should be called in the constructor and the edits should not be in the setters, not

     /** * Write a description of class LoanTest here. * */public class Loan {  private double annualInterestRate;  private int numberOfYears;  private double loanAmount;  private java.util.Date loanDate;  /** Default constructor */  public Loan() {    this(2.5, 1, 1000);  }  /** Construct a loan with specified annual interest rate,      number of years and loan amount     */  public Loan(double annualInterestRate, int numberOfYears,double loanAmount){    if(loanAmount <= 0)    {        throw new IllegalArgumentException("loan must be greater than 0");       } ...

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