522,883 views
15 votes
15 votes
Create a class SavingsAccount. Use a static class variable to store the annualInterestRate for each of the savers. 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 balance by annualInterestRate divided by 12;

User Hkf
by
2.8k points

1 Answer

15 votes
15 votes

Answer:

Step-by-step explanation:

The following code is written in Java and creates the requested variables inside the SavingsAccount class, then it creates a contructor method to add a value to the savingsBalance per object creation. And finally creates a calculateMonthlyInterest method to calculate the interest through the arithmetic operation provided in the question...

public class SavingsAccount {

static double annualInterestRate = 0.03;

private double savingsBalance;

public void SavingsAccount(double savingsBalance) {

this.savingsBalance = savingsBalance;

}

public double calculateMonthlyInterest() {

return ((savingsBalance * annualInterestRate) / 12);

}

}

User Apurva
by
2.6k points