Writing your own classes β and collecting the most predictable FRQ points on the exam.
Home β Unit 3
FRQ 2 hands you a description and asks for a complete class. The structure is the same every year β private instance variables, a constructor that initializes all of them, and methods. Learn the shape once, collect the points every time.
public class BankAccount {
// 1. instance variables β ALWAYS private
private String owner;
private double balance;
// 2. constructor β same name as class, no return type
public BankAccount(String o, double b) {
owner = o;
balance = b;
}
// 3. methods β accessor (returns info)β¦
public double getBalance() {
return balance;
}
// β¦and mutator (changes state)
public void deposit(double amount) {
balance += amount;
}
}
Graders award points for: the class header, private instance variables, a working constructor, correct method signatures, and correct method logic. The signatures are free points β copy the method names, parameter types, and return types exactly as the problem states them. A typo in a signature can cost the point even if your logic is perfect.
this and object referencesWhen a parameter name shadows an instance variable, this.name = name;
says "the object's variable = the parameter." Avoid the issue entirely by giving
parameters different names (like o and b above) β allowed,
simpler, fewer mistakes under time pressure.
Player?private?public class Counter {
private int count;
public Counter() { count = 0; }
public void bump() { count += 2; }
public int getCount() { return count; }
}
// elsewhere:
Counter c = new Counter();
c.bump();
c.bump();
c.bump();
System.out.println(c.getCount());
public void Player(...)) β it becomes a regular method.name = name; when parameter shadows the field (assigns the parameter to itself). Use this.name = name; or different names.I grade them the way readers do β point by point, with the why. It's the fastest FRQ improvement there is.
Ask about tutoring →