Before you start, plan your time wisely. There will be 4 FRQs, each have 2 parts, 8 pieces of code in total. You have 90 minutes, should spend about 20 minutes on each FRQ and leave a good buffer for reviewing and verifying. Here are the steps to work on FRQs:

A. Read the whole spec thoroughly. Out of the 20 minutes for each FRQ, you should spend at least 10 minutes on reading the specifications and make sure you __ understand the question completely__. You won't be able to write correct code if you don't understand the question correctly. Ask yourself:

- How many classes are there? Are they parent/child classes? If not, what are the relationships among these classes?
- What are the instance variables, constructors and methods of each class? Which of them are private? are there any static members? if yes, are they private or public?
- What does each method do? what is the input? what is the output?

B. For part (a), do NOT start writing code until step 3.

- Use the examples provided to verify the input, output and functionality of the method
- Manually work on the examples to complete the functionality, note down what other info is needed in your manual process
- Turn the outcome of step B1 above into method header; turn the process in step B2 above into method body (your notes in step B2 may tell you what variables, or method calls you'll use).

C. For part (b), do NOT start writing code until step 3.

- Use the examples provided to verify the input, output and functionality of the method
- Manually work on the examples to complete the functionality, note down what other info is needed in your manual process
- Turn the outcome of step B1 above into method header; turn the process in step B2 above into method body (your notes in step B2 may tell you what variables, or method calls you'll use).

E. Example: Q1 of 2018 FRQ

F. Practice of the Week: Q4 of 2018 FRQ - **due midnight PST, 2/11/2019.** Please create a file in your personal folder named TP2-2018FRQ4 and save your code there.

1 class

1 class

instance variable:

goalDistance

maxHops

One constructor for the FrogSimulation class

3 instance methods: 2 public and 1 private

1 private 2 public methods. All instance methods

hopDistance returns an int representing the distance, in inches, that the frog moves when he hops

runSimulations: Input: Runs (int num) simulations

Output: Returns proportion(double) of frogs that passed the goal.

simulate return a boolean. True if frog passes/reaches the goal successfully ( >= ). Else returns false

hopDistance() - returns frog's hopping distance

simulate() - returns true if frog reaches goalDistance (instance variable)

runSimulations() - returns a proportion of successful attempts of frog reaching goal vs unsuccessful

simulate: input: null

output: boolean tells you if the distance in the hopdistance reaches the goal in the needed amount of moves

runSimulate: input: null

output: percent of simulates that finish the goal.

public boolean simulate(){

frogsimulation sim = new frogsimulation(goalDistance, maxHops);

double Frog_current_position = 0.0;

boolean Goal_complete = false;

for(int i;i<sim.maxHops;i++){

Frog_current_position += hopDistance();

if(Frog_current_position>=(double)sim.goalDistance){

Goal_complete = true;

break;

}

if(Frog_current_position<0){

break;

}

}

return Goal_complete;

}

public double runSimulation(int num){

int runs = 0;

int complete_runs = 0;

boolean completion = false;

for(int i=0;i<num;i++){

completion = simulate();

runs++;

if(completion){

complete_runs++;

}

}

System.out.println((double)complete_runs/runs);

}

public boolean simulate(){

FrogSimulation f = new FrogSimulation(goalDistance,maxHops);

}

double currentPos = 0;

boolean cross = false;

for(int i=0;i<f.maxHops;i++){

currentPos += hopDistance;

if(currentPos>=f.goalDistance){

cross = true;

break;

}else if(currentPos<0){

break;

}

}

return cross;

}

public double runSimulations(int num){

int numTrue=0;

double prop =0;

for(int i=0;i<num;i++){

boolean temp = simulate();

if(temp==true){

numTrue++;

}

prop = numTrue/num;

return prop;

}

public String runSimulations(int simulations) {

// Assume simulate runs correctly

double success = 0;

for (int i = 0; i < simulations; i++ ) {

simulate();

if (cross == true)

success++

}

double successRate = success/simulations;

successRate = successRate * 100;

return "" + successRate + "%";

}

public double runSimulations(int num){

double a =0.0;

for(int i =0; i < num; i++){

if(simulate() = true){

a++

}

}

return (a/num)

}

public boolean simulate(){

int a = 0;

for(int i=0; i <maxHops; i++){

a += hogDistance();

}

if(a >= 24){

return true;

}

elif(a <0){

return false;

}

else{

return false;

}

}

public boolean simulate(){

FrogSimulation x = new FrogSimulations(goalDistance, maxHops);

if(hopDistance() >= goalDistance)

return true;

else if(hopDistance() < 0)

return false;

else if(maxHops == 5 && hopDistance() != goalDistance)

return false;

}

public double runSimulations(int num){

int false = 0;

double success;

double rV = success/num;

for(int i = 0; i < num; i++){

if(simulate() = true)

success++;

else

return false;

}

return rV;

}