Conclusion (Jason)

The “Classes” section gives a simple guide to handling Classes FRQs in APCSA. It explains key ideas like writing class headers, constructors, and methods, and keeping instance variables private. Following these steps makes your code organized and clear, which helps earn points on the exam.

Tips

  1. Follow Instructions: Always match class headers, constructors, and method details to what’s asked in the question.

  2. Keep it Simple: Use this.variable = parameter; to set instance variables in constructors.

  3. Check Scoping: Class and method headers should usually be public, and instance variables should always be private.

Homework! (Jason)

2017 FRQ, Question 2 - Classes

Homework over here…

2017 FRQ, Question 2, Classes

Example 1

Example 2

Final

public interface StudyPractice {
    String getProblem();
    void nextProblem();
}

public class MultPractice implements StudyPractice {
    private int first;
    private int second;

    public MultPractice(int first, int second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public String getProblem() {
        return first + " TIMES " + second;
    }

    @Override
    public void nextProblem() {
        second++;
    }
}

MultPractice practice= new MultPractice(1,3);
System.out.println(practice.getProblem());
practice.nextProblem();
System.out.println(practice.getProblem());

1 TIMES 3
1 TIMES 4