Create 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 modifyInterestRate that sets the annualInterestRate to a new value.Write a program to test class SavingsAccount. Instantiate two SavingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for both savers.

Question
Asked Oct 10, 2019
838 views

Create 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 modifyInterestRate that sets the annualInterestRate to a new value.

Write a program to test class SavingsAccount. Instantiate two SavingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for both savers.

 

 

check_circle

Expert Answer

Step 1

The following source code will perform the functions as specified in the question.

Step 2

Source Code

class SavingsAccount {         

    private static float annuallInterestRate;

    private float savingsBalance;

    private float monthlyInterest;

    public SavingsAccount(float savingsBalance) {

        this.savingsBalance = savingsBalance;

    }

    public void calculateMonthlyInterest() {

        this.monthlyInterest = (savingsBalance * annuallInterestRate) / 12;

        System.out.println("The next month interest is: $ " + this.monthlyInterest);

    }

    public static void modifyInterestRate(float interestRate) {

        annuallInterestRate = interestRate;

    }

    private void calculateSavings() {

        savingsBalance += this.monthlyInterest;

    }

    public void displaySavings() {

        calculateSavings();

        System.out.println("The new balance is : $ " + savingsBalance);

    }

}

public class Test_SavingsAccount{

    public static void main(String[] args) {

    &...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: What are the disadvantages of Android Pie?

A: Android pie is 9th edition of Android. It has massive software updates which make it easier to use a...

question_answer

Q: m2 separated by a distance d is given by:F = Gm1m2d 2where G is the universal gravitational constant...

A: A C++  program to display the gravitational force between two objects is given below;Program code://...

question_answer

Q: Explain how to convert the letters A, B and C to decimal.

A: Decimal Number SystemDecimal number system is a base- 10 number system. It has 10 symbols, the symbo...

question_answer

Q: Write a statement that outputs variable numObjects. End with a newline. Program will be tested with ...

A: As you have not specified the programming language, we are solving this question using Java programm...

question_answer

Q: Assignment (Math application):Write a program that prompts the user to enter a 3 x 3 matrix of doubl...

A: Program Instructions:In main method, call methods createArray() and isMarkovMatrix().In method creat...

question_answer

Q: Code should be in C++ Absolute Value Template: Write a function template that accepts an argument an...

A: Since Function Templates are used to handle all possible data types you can say generic data type at...

question_answer

Q: Assume that a double variable named alpha contains the value of an angle in radians. Compose a C++ s...

A: Below program uses following c++ functionsstd::setw, std:setfill, setprecision(int n) defined under ...

question_answer

Q: Assign secretID with firstName, a space, and lastName. Ex: If firstName is Barry and lastName is All...

A: To correct the given program code to assign the secretID as firstName,  space, and lastName, as show...

question_answer

Q: What are the Windows 2016 "flavors"?

A: Windows Server 2016 comes in 3 flavors, which are, Server Core (no GUI), Server with Desktop Experie...