FRQ #1 METHODS AND CONTROL STRUCTURES
The first free response question (FRQ) of the AP Computer Science A exam will be on Methods and Control structures.
You will be provided with the method header with some parameter variables and other methods that you will need to call in the solution. You may need to use Math or string methods.
Question #1 will probably involve:
a for-loop that probably uses the method's parameter variables
an if statement, probably inside the loop
calls to other class methods given to you
a numerical string value that is calculated by the loop and returned at the end of the method
if the question has 2 parts, 1 part will probably require a loop and the other just an expression
For question #1, you will get points for:
constructing the loop correctly
calling the correct methods
calculating the correct value
returning the value
The following FRQ is a good example of what to expect for Question #1 on the exam.
Don't worry, I will walk you through this one!
First, I recommend circling the information given that you will need to use:
the parameters year1 and year2
the isLeapYear(year) method
I also recommend circling the return type of what you need to return.
In this case, the return type of numberOfLeapYears is int and you need to calculate the number of leap years between year1 and year2 and return it.
First, I declared a variable for this return value and return it at the end of the method (this is worth 1 point).
Next, I started to make a plan for the loop.
I know that I want to count the number of leap years between year1 and year2, so I decided to use a for loop that starts at year1 and ends at year2.
It is usually easiest to use a for loop if you know how many times the loop should execute using the given information.
Usually, the method parameters will be used for the initial and ending values of the loop variable.
The preconditions stated for the method tells us that we don't have to worry about year1 and year2 being out of order or below zero (there is no need to waste time on error checking these values).
Here is the loop I came up with:
Notice that we were given a method to use called isLeapYear().
The method header says that it returns a boolean.
Any method that starts with the word "is" usually returns a boolean.
This is a signal that we should use it in an if statement!
The method will usually take an argument.
If it is used inside the loop, this could be the loop variable.
I put all the code together to solve the problem!
On the exam, part A was worth 5 points using the rubric below:
In part B of this FRQ we need to write the code inside a static method dayOfWeek, which returns the integer value representing the day of the week for the given date (month, day, year), where:
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
This may seem difficult at first, but there are helper method given to you that do most of the work.
You just need to put them together to calculate the value.
The helper methods given to you are:
firstDayOfYear(year) returns the integer value representing the day of the week for the first day of the year. For example, since 2019 began on a Tuesday, firstDayOfYear(2019) returns 2.
dayOfYear(month, day, year) returns n, where month day, and year specify the nth day of the year. For the first day of the year, January 1, the value 1 is returned. This method accounts for whether year is a leap year. For example, dayOfYear(3, 1, 2017) returns 60, since 2017 is not a leap year, while dayOfYear(3, 1, 2016) returns 61, since 2016 is a leap year.
If you know that 1/1/2019 was a Tuesday (2) using the firstDayYear method, and you know that today is the nth day of the year using the dayOfYear method, you can figure out what day of the week today is by adding those together.
Question: If firstDayOfYear(2019) returns 2 for a Tuesday for 1/1/2019, what day of the week is 1/4/2019?
Answer: Friday (5)
Question: What expression could be used to return the right value for the day of the week (5) for 1/4/2019 given that firstDayOfYear(2019) returns 2 and dayOfYear(1, 4, 2019) returns 4?
Answer: firstDayOfYear(2019) + dayOfYear(1, 4, 2019) - 1. You must start at the firstDayOfYear and add on the days following up until that date - 1 since you start counting at 1.
Question: If firstDayOfYear(2019) returns 2 for a Tuesday for 1/1/2010, what day of the week is 1/8/2019?
Answer: Tuesday (2). Since 1/1/2019 is a Tuesday, 1/8/2019 is 7 days later so it would fall on the same day of the week.
If we used the formula in the question above for the 1/8/2019, we would get a 9:
firstDayOfYear(2019) + dayOfYear(1, 8, 2019) - 1 = 2 + 8 - 1 = 9
But unfortunately, there is no 9th day of the week.
There are only 7 days in the week, so when we reach a Sunday, we must start back at 0.
This is a place where the mod operator % is useful.
Note that 9 % 7 == 2 which means that 1/8/2019 is the 2nd day of the week.
So, this part of the FRQ involves using an expression that will use the mod operator %.
Remember these tips about when to use the mod operator:
Use mod whenever you need to wrap around to the front if the values goes over the limit (num % limit). For example here fore weekdays or for hours and minutes.
Use mod to check for odd or even numbers (num % 2 == 1) is odd and (num % 2 == 0) is even. Actually, you can use it to check if any number is evenly divisible by another (num1 % num2 == 0)
Use mod to get the last digit from an integer number (num % 10 = last digit on right).
Question: Which expression would you use to return the right value for the day of the week (2) for 1/8/2019 given that firstDayOfYear(2019) returns 2 and dayOfYear(1, 8, 2019) returns 8?
Answer: (firstDayOfYear(2019) + dayOfYear(1, 8, 2019) - 1) % 7 would return (2 + 8 - 1) % 7 = 2.
Finally, after all of that explanation, I can show you the code I wrote for the method dayOfWeek:
On the exam, part B was worth 4 points using the rubric below:
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 these again before the exam.