Hi,
im trying to creat a savingsAccount class and its suppose to have a method that caluculates monthly interest and a modify interest rate method that sets the annual interest rate to a new value.
heres what it says
"
Create class SavingsAccount. Use a static class variable to store the annualInterestRate 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 mehtod 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 driver 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 and print the new balances for each of the savers. Then set the anualInterestRate to 5% and calculate the next month's interest and print the new balances for each of the savers.
"
then I have to write a test program to see how it runs:
I think i need to use set and get methods for the modify annual interest rate method.
i have this for the savings account class but i know im far off from the finished product, can anyone help me out?
Code:package java.SavingsAccount; import java.text.DecimalFormat; import java.util.Locale; public class SavingsAccount extends Object{ private int savingsBalance; //amount saver has on deposit private static double annualInterestRate; public void setMonthlyInterestRate(double annualInterestRate) { setMIR(annualInterestRate); } public static double getModifyInterestRate() { return annualInterestRate; } public int calculateMonthlyInterest(savingsBalance) { savingsBalance= (savingsBalance * annualInterestRate)/ 12; } }


Reply With Quote


Bookmarks