Live rate versus locked-in rate

A credit union's savings software uses the Java class below. Each account computes one year of interest two ways: with the rate shared by the whole class, and with the rate copied when the account was opened.


Java
public class Account {
    private static double rate = 0.02;
    private double balance;
    private double lockedRate;

    public Account(double balance) {
        this.balance = balance;
        lockedRate = rate;
    }

    public static void setRate(double r) {
        rate = r;
    }

    public double currentInterest() {
        return balance * rate;
    }

    public double lockedInterest() {
        return balance * lockedRate;
    }
}


Another class then runs these statements:


Java
Account x = new Account(1000.0);
Account.setRate(0.05);
Account y = new Account(500.0);
y.setRate(0.03);


After the last statement, find the value returned by each of x.currentInterest(), x.lockedInterest(), y.currentInterest() and y.lockedInterest(). Give each in dollars to two decimal places.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Class Attributes and Methods Questions: