public class FrogSimulation
{
    /** Distance, in inches, from the starting position to the goal. */
    private int goalDistance;
    /** Maximum number of hops allowed to reach the goal. */
    private int maxHops;
    /** Constructs a FrogSimulation where dist is the distance, in inches, from the starting
    * position to the goal, and numHops is the maximum number of hops allowed to reach the goal.
    * Precondition: dist > 0; numHops > 0
    */
    public FrogSimulation(int dist, int numHops)
{
    goalDistance = dist;
    maxHops = numHops;
}
    /** Returns an integer representing the distance, in inches, to be moved when the frog hops.
     */
    private int hopDistance()
    { /* implementation not shown */ }
    /** Simulates a frog attempting to reach the goal as described in part (a).
    *  Returns true if the frog successfully reached or passed the goal during the simulation;
    * false otherwise.
    */
    public boolean simulate()
    { /* to be implemented in part (a) */ }
    /** Runs num simulations and returns the proportion of simulations in which the frog
    * successfully reached or passed the goal.
    * Precondition: num > 0
    */
    public double runSimulations(int num)
    { /* to be implemented in part (b) */ }
}
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.

Part A

Write the simulate method, which simulates the frog attempting to hop in a straight line to a goal from the frog's starting position of 0 within a maximum number of hops. The method returns true if the frog successfully reached the goal within the maximum number of hops; otherwise, the method returns false.

public boolean stimulate()
{
   int position = 0; // the initial position of frog
   boolean passedGoal = false; // boolean that tells us whether the frog has passed the goal or not
   int numHops = 0 // how many hops the frog has taken represented in an integer

   while(!passedGoal && position >= 0 && numHops < maxHops) // De Morgan's law
   {
    position += hopDistance(); // will get our integer and see how far of a position it is
    if(position >= goalDistance)
    {
        passedGoal = true; // when while loop is done, the loop will be exited
    }
    numHops++; // increments the hops until number of hoops increases max hops
   }
   return passedGoal; // tells us whether frog has passed the goal or not
}

Part B

Write the runSimulations method, which performs a given number of simulations and returns the proportion of simulations in which the frog successfully reached or passed the goal. For example, if the parameter passed to runSimulations is 400, and 100 of the 400 simulate method calls returned true, then the runSimulations method should return 0.25. Complete method runSimulations below. Assume that simulate works as specified, regardless of what you wrote in part (a). You must use simulate appropriately to receive full credit.

public double runSimulation(int num) // int is the number of times we want to run the loop
{
    int count = 0;
    for (int i = 0; i < num; i++){ 
        if (simulate()){
            count++; // if it's successful, the hops will increase by 1
        }
    }
    return (double) count / num; // gives a proportion of successes
}