The second free response question (FRQ) of the AP Computer Science A exam will be on classes, where students design and implement a described class. This question involves creating a class with private instance variables and public methods. The College Board will provide a description of the class and the methods. This question does not involve more complex topics such as arrays.
To succeed on the FRQ Question #2 on Classes you must know how to:
Create a class using public class Classname { }
Write a constructor with the same name as the class and no return type. This constructor will probably have a parameter that is assigned to an instance variable and will need to assign default values to the other instance variables.
Write public methods in the class that use the instance variables as well as parameters and return values. These methods will probably use if statements but not more complex coding. One of these methods will probably be an accessor method that returns an instance variable or a calculated value that is dependent on the instance variables, and one will probably be a mutator method that changes the value of an instance variable.
The following FRQ is a good example of what to expect for Question #2 on the exam.
Don't worry, I will walk you through this one!
WRITING THE CLASS HEADER & CONSTRUCTOR:
First, I read through the problem statement and determined the instance variables required for this class. During the exam, it helps to circle the words that are important and may describe the instance variables. It may also help to identify the variables that are needed for the constructor and the accessor/mutator methods.
You will receive at least 1 point if you write the class header and a constructor that has the same name as the class and no return type. You will receive another point for creating private instance variables inside the class.
Below, I completed the class definition with the class name, the instance variables, and the constructor. Remember that for this problem a StepTracker object is created (with a constructor) with a parameter that defines the minimum number of steps that must be taken for a day to be considered active. Therefore, the constructor should have a parameter that it assigns to an instance variable. It should also assign default values to the other instance variables.
Here is a rubric for the instance variables and the constructor for this problem.
WRITING THE ACCESSOR METHOD ACTIVEDAYS:
Each method in this FRQ is worth 1 - 3 points. The method header is usually worth 1 point and the code in the method body is worth another point or two depending on how complex it is.
This problem asks you to write a simple accessor method called activeDays which returns the number of active days (which should be an instance variable) for 1 point.
This is what I came up with for the activeDays() method:
Here is the rubric for the accessor method activeDays() for this problem. The second column identifies small mistakes that will still earn the point but the third column contains larger mistakes that would result in not earning the point.
WRITING THE MUTATOR METHOD ADDDAILYSTEPS:
This problem also asks you to write a more complex mutator method called addDailySteps worth 3 points. This method will need to change more than one instance variable. Notice the comments in the sample code execution:
It is important to consider each of the instance variables and whether this method should change them or not.
This is what I came up with for the activeDailySteps() method:
Here is the rubric for the mutator method for this problem. The second column identifies small mistakes that will still earn the point but the third column contains larger mistakes that would result in not earning the point.
WRITING THE ACCESSOR METHOD AVERAGESTEPS:
Finally, this problem asks you to write a more complex accessor method which uses the instance variables to calculate and return the averageSteps for 2 points. This method returns the average number of steps per day, calculated by dividing the total number of steps taken by the number of days tracked.
The complex accessor method averageSteps() must calculate the average number of steps from your instance variables. Notice that the first time it is called in the sample code execution, it returns 0.0 since there are no steps recorded. This avoids a divide by 0 error.
This is what I came up with for the averageSteps() method:
Here is the rubric for the averageSteps method for this problem.
Here is a picture of my entire solution. I had to tape on an additional piece of paper haha
For the FRQ evidence, there is no Google Form.
I printed out the question above as well as TWO additional practice FRQ questions for you to complete.
I have the solution to these practice FRQ questions, so when you think you have the answer, come meet with me and I will show them to you.
RECOMMENDATION: For each question, set a timer for 22 minutes and 30 seconds (to simulate the amount of time that you will actually have) and see how you do! I will show you the answer after with the scoring rubric so you can see how many points you would have received!
PLEASE, don't just search around on Google and copy down the answer.
This grade is for completion, not accuracy, so you would only be hurting yourself.
TREAT THESE PRACTICE FRQ QUESTIONS LIKE GOLD.
Put them somewhere safe and review them again before the exam.