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

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

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

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

  • Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet...

    Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet object holds integers in the range 0-100 Represented by an array of booleans, such that array element a[i] is set to true if integer i is in the set, and false otherwise Create these constructors and methods for the class IntegerSet() public IntegerSet union(IntegerSet iSet) public IntegerSet intersection(IntegerSet iSet) public IntegerSet insertElement(int data) public IntegerSet deleteElement(int data) public boolean isEqualTo(IntegerSet iSet) public String toString()...

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

  • JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design...

    JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design an abstract class named BankAccount to hold the following data for a bank account: • Balance • Number of deposits this month • Number of withdrawals • Annual interest rate • Monthly service charges The class should have the following methods: Constructor:   The constructor should accept arguments for the balance and annual interest rate. deposit:             A method that accepts an argument for the amount of...

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