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.
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:
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.
Unlock full course notes by signing up
Tracking cart-line quantities
A Java shopping program uses the class below. In a fresh run, the statements shown execute inside main in order. Complete the table after each call using exact integer numbers of units.
Resolving two meanings of points
A Java game uses the following class to preview a player's score. Inside main, Score score = new Score(); has executed. What does score.projected(3) return? Give your answer in points, to the nearest whole point.
When does the meter class get ready?
A utility company models its water meters with the Java class below. The main method of another class runs the four statements shown after it. Put the lines the program prints in the order they appear on the console.
Moving counts through a static operation
A Java ticket office uses the class below. In a fresh run, the shown statements execute inside main, with a and b referring to distinct objects. Select every correct statement about transfer and the resulting state.