AP CSA class design is not about writing more code. It is about deciding what each object should know and what each object should do. Since inheritance is no longer the focus for AP CSA, strong object composition matters even more.
Scenario: gradebook
A StudentRecord object can store a student name and a list of scores. A Gradebook can store many records and compute class-level summaries.
public class StudentRecord
{
private String name;
private ArrayList<Integer> scores;
public StudentRecord(String studentName)
{
name = studentName;
scores = new ArrayList<Integer>();
}
public void addScore(int score)
{
scores.add(score);
}
}
Who owns the method?
A method that calculates one student's average belongs in StudentRecord. A method that finds the highest average across all students belongs in Gradebook. This separation keeps each class focused.
Common mistakes
- Making every variable public instead of using methods.
- Putting class-wide behavior inside one student object.
- Forgetting to initialize an ArrayList in the constructor.
- Returning internal lists directly when mutation should be controlled.
Practice prompt
Design a CourseRoster class that stores StudentRecord objects. Decide which class should handle adding a score, finding one student's average, and finding the class average.
