Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create class SavingsAccount. Use a static variable annualInterestRate to store t

ID: 441319 • Letter: C

Question

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 savingBalance indicating the amount that saver currently has no deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingBalance by annualInterestRate divided by 12- this interest should be added to savingsBalance. Provide static method ModifyInterestRate to set the annualInterestRate to a new value. Write an application to test class SavingsAccount. Create two savingAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and display the new balances for both savers. Then set the annual InterestRate to 5%, calculate the next month

Explanation / Answer

public class SavingsAccount { //variable to store annual interest rate static private double annualInterestRate; private double savingBalance; //constructor method public SavingsAccount() { } //Constructor method public SavingsAccount(double savingBalance) { this.savingBalance=savingBalance; } //Get saving balance public double getSavingBalance() { return this.savingBalance; } // Modify interest rate by setting annual interest rate to a new value public static void modifyInterestRate(double newInterestRate) { annualInterestRate=newInterestRate; } //Method to calculate monthly interest public void calculateMonthlyInterest() { double monthlyI; monthlyI= (double)(this.savingBalance*annualInterestRate/12); this.savingBalance+=monthlyI; } public static void main(String[] args) { // To test the class designed above //Instantiate 2 saving account objects saver1 and saver2 SavingsAccount saver1, saver2; saver1 = new SavingsAccount (2000.0); saver2= new SavingsAccount (3000.0); //Set the annual interest rate to 4%=0.04 SavingsAccount.modifyInterestRate (0.04); //Calculate monthly interest saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); //Print out the new balances for both savers System.out.println("This month: Saver 1 balance= "+ saver1.getSavingBalance()); System.out.println("Saver 2 balance= "+ saver2.getSavingBalance()); //Change annual interest rate to 5%=0.05 SavingsAccount.modifyInterestRate(0.05); //Calculate the next month interest rate and print out balances saver1.calculateMonthlyInterest(); saver2.calculateMonthlyInterest(); System.out.println("Next month: Saver 1 balance= "+ saver1.getSavingBalance()); System.out.println("Saver 2 balance= "+ saver2.getSavingBalance()); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote