Practice a College Board-style Class Design free response — instance variables, a constructor, accessor and mutator methods, and a static counter. Write your Java, then reveal the model answer to see exactly what earns each point.
Design a class named BankAccount that stores a balance. This mirrors the exam’s Class Design question. The class should encapsulate its data.
A
Declare a private instance variable for the balance and write a constructor that initializes it from a parameter.
✓ Model answer
public class BankAccount {
private double balance;
public BankAccount(double startingBalance) {
this.balance = startingBalance;
}
}
Why it scores: Declares the instance variable as private (encapsulation), and the constructor has the class name, no return type, and initializes the field from the parameter. A return type on the constructor or a public field would lose points.
B
Write an accessor method getBalance and a mutator method deposit(double amount) that adds to the balance.
✓ Model answer
public double getBalance() {
return balance;
}
public void deposit(double amount) {
balance += amount;
}
Why it scores: The accessor returns the balance with the correct return type; the mutator returns void and updates the instance variable. Giving deposit a non-void return type, or having getBalance change state, would lose credit.
C
Add a static variable that counts how many BankAccount objects have been created, and explain why it is static.
✓ Model answer
private static int accountCount = 0;
… and inside the constructor add accountCount++;
It is static because the count belongs to the class as a whole, not to any single object — there is one shared copy that every constructor call increments, so all objects agree on the total.
Why it scores: Declares a static variable and increments it in the constructor, and correctly explains that a shared class-level count must be static (an instance variable would give each object its own separate counter).
How to score points on AP CSA free response
Make instance variables private to show encapsulation.
Constructors have no return type and initialize the fields.
Accessors return a value; mutators return void and change state.
Use static for class-wide data shared by all objects.
Answer the verb. "Write" wants complete Java; "explain" wants reasoning.