Answer to Question #164825 in Java | JSP | JSF for aj

Question #164825

Write a java program that create a class savacnt, use a static variable anintrate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savbal indicating the amount the saver currently has ondep. Provide method calcmonthint to calculate the monthly interest by multiplying the savbal by anintrate divided by 12 this interest should be added to savbal. Provide a static method modiintrate that sets the anintrate to a new value.


Write a program to test class savacnt. Instantiate two savacnt objects, savel and save2, with balances 4000 and 6000, respectively. Set anintrate to 5%, then calculate the monthly interest and print the new balances for both savers. Then set the anintrate to 6%, calculate the next month's interest and print the new balances for both savers.


1
Expert's answer
2021-02-18T19:00:35-0500
public class SaveAccount {
    public static double anintrate;
    private double savbal;

    public SaveAccount(double savbal) {
        this.savbal = savbal;
    }

    public double calcmonthint() {
        return savbal + savbal * anintrate / 12;
    }

    public static void modiintrate(double anintrate) {
        SaveAccount.anintrate = anintrate;
    }
    public static void main(String[] args) {
        modiintrate(5);

        SaveAccount save1 = new SaveAccount(4000);
        SaveAccount save2 = new SaveAccount(6000);

        System.out.println("Save 1 account after the first month: " + save1.calcmonthint());
        System.out.println("Save 2 account after the first month: " + save2.calcmonthint());

        modiintrate(6);

        System.out.println("Save 1 account after the second month: " + save1.calcmonthint());
        System.out.println("Save 2 account after the second month: " + save2.calcmonthint());
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog