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
-
Follow Instructions: Always match class headers, constructors, and method details to what’s asked in the question.
-
Keep it Simple: Use
this.variable = parameter;
to set instance variables in constructors. -
Check Scoping: Class and method headers should usually be
public
, and instance variables should always beprivate
.
Homework! (Jason)
2017 FRQ, Question 2 - Classes
Homework over here…
public class MultPractice implements StudyPractice {
// Instance variables to store the factors for the multiplication problem
private int primary; // The fixed factor in the multiplication
private int variable; // The changing factor in the multiplication
// Constructor to set the initial values of the factors
public MultPractice(int initialFactor, int changingFactor) {
primary = initialFactor;
variable = changingFactor;
}
// Method to return the current multiplication problem as a readable string
public String getProblem() {
return primary + "TIMES" + variable;
}
// Method to increment the variable factor to generate the next problem
public void nextProblem() {
variable++;
}
}
StudyPractice p1 = new MultPractice(7, 3);
System.out.println(p1.getProblem());
| public class MultPractice implements StudyPractice {
| // Instance variables to store the factors for the multiplication problem
| private int primary; // The fixed factor in the multiplication
| private int variable; // The changing factor in the multiplication
|
| // Constructor to set the initial values of the factors
| public MultPractice(int initialFactor, int changingFactor) {
| primary = initialFactor;
| variable = changingFactor;
| }
|
| // Method to return the current multiplication problem as a readable string
| public String getProblem() {
| return primary + "TIMES" + variable;
| }
|
| // Method to increment the variable factor to generate the next problem
| public void nextProblem() {
| variable++;
| }
| }
Unresolved dependencies:
- class StudyPractice