FRQ 1 Methods and Control Structures
The first free response question, Methods and Control Structures, tests students on units 1 - 4, with a special focus on calling method (unit 2) and including if statements (unit 3) and / or loops (unit 4). There will not be any data structures used in this question. In these questions, you will be writing the body of a method or constructor. The header for the method or constructor is provided for you.
Review and attempt all parts of the question.
Question 1 has a part a and part b. While some believe that part a is easier than part b, that isn't always the case for students. Some will understand the directions for part b better, making that part of the question easier for them to write the solution. Be sure that you attempt each part, rather than skipping part b, because you hit a road block with part a. While solving part b, it is possible that you will realize what you need to do for part a.
This question will supply you with a partially written class (or maybe two classes). You will need to complete a method (or constructor) for this partially written class. The "tools" you will need can be found in the following places:
Instance variables for the class** For example, 2024 FRQ #1 contains the instance variable private int currentFood;
(The instance variables might not be provided in the code directly, since they don't want to give you clues to how to write question 2. They might be provided in comments or in the directions. In 2024, they are all provided in the code.) You will need to use currentFood
in either the solution of part a or b or both. In BlueBook, highlight this instance variable and make a note that you need to use it.
Return type of the method you need to write
If there is a return type other than void
, you will need to calculate and return that value. In BlueBook, highlight the return type and make a note for yourself. If it is void
, note that you will either need to update the instance variables or that you aren't calculating something. If it is something other than void
, you will need to make a note to remind yourself that you are calculating something and that you need to remember to return it. Too often, students do the hard part of calculating the return value and then forget to write return value; at the end of their method. Doh!!
In 2024 FRQ #1, the simulateOneDay
method has a void
return type. In the description, it says "The method determines the amount of food taken from the feeder on this day and updates the currentFood
instance variable." You need to update the instance variable in this method, so you will have something like currentFood = //something;
in your code.
Part b of this question asks you to write simulateManyDays
, which has an int
for a return type. This means that you will need to produce a new int
value to return. The description says "The simulation returns the number of days that birds or a bear found food at the feeder." In BlueBook, highlight these sentence that tell you what you are returning or what you are updating.
Look at the parameters for the methods.
The parameters are provided because you need to use them in your solution. If you have written a solution and never used the provided parameters, you have misunderstood what you needed to do. In BlueBook, highlight the parameters and make a note to yourself that you need to use them in your solutions. In 2024 FRQ #1 part a, the simulateOneDay
method has a parameter int numBirds
. The descriptions says that "each bird at the feeder consumes the same amount of food". It goes on to talk about how that amount of food is calculated. The amount of food eaten is "randomly generated" (Hello, Math.random()
!). It goes on to give examples of how if the amount eaten by a bird is 11 grams and that their are 10 birds, the total amount of 110 grams has been consumed by birds (result of Math.random() calculation * numBirds
). In part b, you have numBirds
and numDays
to use.
Use methods provided, even the ones that you wrote.
If a method was provided that you didn't have to write, you have to use it. They won't provide a helper method if you aren't expected to use it. Check out 2024 FRQ #4. This question provides an entire class as a helper class. This class has methods getRow
and getCol
. You will need to use these methods in the solution of part a or b or both. You might also be asked to use the method you wrote in part a.
Look at 2024 FRQ #1, right before you are asked to write the method, you will see the sentences: "Assume that simulateOneDay
works as intended, regardless of what you wrote in part (a). You must use simulateOneDay
appropriately in order to receive full credit." In BlueBook, highlight these sentences and make a note that you have to call simulateOneDay
in your solution.
Recognize when to use Math.random()
This question type lends itself well to the use of Math.random()
. You should practice shifting the range of values when using Math.random()
.
For example, if you are asked to produce a value between 10 and 50 inclusive, first identify how many numbers are in this range by adding 1 to the difference of the values (50 - 10) + 1. The range of numbers here is 41. And then you need to shift the values over to start at 10. The formula to use is (int)(Math.random() * the number of values in the range) + the shift
. In this example, you would want to use (int)(Math.random() 41) +10
.
You may be asked to generate the random number once for the call to the method or in a loop. How do you know? Well, in 2024 FRQ #1, there is no loop, since you are only simulating one day. You will want this generation to happen in the method, so that it is a new value every time the method is called. If it wants you to complete the random generation in a loop, it might say "assigns a newly generated random value for each..."
Recognize when to use an if statement
Not all parts will have an if statement, but they can. In the 2024 FRQ #1 part a, there are two if statements used in the solution.
The first if statement is for when a bear comes to the feeder. So, either there is a bear or there isn't a bear. The description says the following as clues to the if statement:
- "simulates
numBirds
or possibly a bear at the feeder" - So there are going to be two different conditions to the simulation.
- "simulation accounts for normal conditions, which occur 95% of the time, and abnormal conditions, which occur 5% of the time" - The percentages mean we will need to use
Math.random()
again. And this gives us the condition for the if statement. We generate a random number and if it is <= 5, then a bear is going to show up, otherwise, we just have birds.
The second place where we need to use an if statement is if we run out of food. The description says "If the simulated food consumed is greater than the amount of food in the feeder..." The word "if" is a clue for us. This also describes the condition we would use, if amount consumed > currentFood
.
Recognize when to use a loop
Not all parts will have a loop, but they can. In the 2024 FRQ #1, part a does not have a loop. It simulates one day at the feeder. Part b, however, simulates numDays
at the feeder. Some clues from the description:
- The description states, "simulate numBirds birds or a bear coming to the feeder on at most numDays consecutive days." We will need to have a loop that iterates at most
numDays
times. The "at most" clause is a clue that this isn't a for
loop situation, otherwise it would've said "iterates numDays
times". We will need a while
loop here and part of the condition is that the number of times we have iterated is <= numDays
.
You can also glean that you need a while
loop by looking at the examples.
- In the first example,
numDays
is 4
, and we have Day 1 thru Day 4 recorded.
- In the second example though,
numDays
is 5
, but we only have Day 1 and Day 2 recorded. So something stopped the loop early. What made it stop early? No food was found at the feeder. There is the other part of your condition. Not only do we need the number of iterations to be <=numDays
, we need currentFood
to not equal 0
.
Other tips:
- Read carefully.
- Pay attention to examples provided.
- Watch your time. Taking too long? Come back to it. It's amazing how your brain will multi-task on it in the background and when you come back, you'll know exactly what to do.
- Double check all your notes when you are finished. Did you use the instance variables, parameters, methods? Did you remember to return a value? These little things can be the difference between earning points and losing points. FRQs are the game of collecting as many points as you can.
Best of luck!! Wishing for you all to earn 5s.
More Resources