Create a class Saving Account. 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 capability. Instantiate two savingsAccount objects, saver1 and saver2, with balances of TSh 20,000.00 and TSh 30,000.00,respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for both savers. Then set the annualInterestRate to 5%, calculate the next month's interest and print the new balances for both savers.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
Solution
SavingAccount.java
package savingsaccount;
/**
*
* @author Archangel Macsika
*/
public class SavingAccount {
private static float annuallInterestRate;
private float savingsBalance;
private float monthlyInterest;
public SavingAccount(float savingsBalance) {
this.savingsBalance = savingsBalance;
}
public void calculateMonthlyInterest() {
this.monthlyInterest = (savingsBalance * annuallInterestRate) / 12;
System.out.println("The monthly interest is TSh: " + this.monthlyInterest);
}
public static void modifyInterestRate(float interestRate) {
annuallInterestRate = interestRate;
}
private void calculateSavings() {
savingsBalance += this.monthlyInterest;
}
public void displaySavings() {
calculateSavings();
System.out.println("The total balance is : $ " + savingsBalance);
}
}
Main Class
package savingsaccount;
/**
*
* @author Archangel Macsika
*/
public class TestClass{
public static void main(String[] args) {
// SavingAccount.annuallInterestRate = 0.15;
SavingAccount saver1=new SavingAccount(45000);
SavingAccount saver2=new SavingAccount(70000);
SavingAccount.modifyInterestRate(2);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
saver1.displaySavings();
saver2.displaySavings();
SavingAccount.modifyInterestRate(3);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
saver1.displaySavings();
saver2.displaySavings();
}
}