Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help debugging this program. I am new to calling and using methods. Thank

ID: 3890986 • Letter: I

Question

I need help debugging this program. I am new to calling and using methods.

Thank you. :)

public class JavaRaceSimulation

{

public static void main (String [] args) {

   JavaRaceSimulation = new JavaRace;Simulation

          

}

  

  

  

public class JavaRaceSimulation

{

  

   int t =1;

   int r = 1;

   int finish = 50; //defines the finish line

   int slow; // for slips

   int characterPositions; //position of character

  

   //use while statement

  

   while (t != finish && r != finish )

   {

       rabbitRace (); //define rabbit method

       turtleRace (); //define turtle method

       display ();

      

  

       for (slow = 0; slow <100000000; slow++)

       {}

  

  

  

   //this statement defines if turtle wins

   if (t >= r)

   {

       System.out.println("Tortoise Wins!");

  

   } else { //else defines if rabbit wins

       System.out.println("Hare wins!");

   }

  

  

   public static void rabbitRace()

   {

       characterPositions = (int)(1+ Math.random() * 10);

       int rabbitPosition [] = {9,12,2};

       if (characterPositions == 1 || characterPositions == 2 )

           r +=9;

       else if (characterPositions == 3)

           r -= 12;

       else if (characterPositions == 4 || characterPositions == 5)

           r -= 2;

       else if (characterPositions == 6 || characterPositions == 7)

           r = 0;

       else if (characterPositions == 8 || characterPositions == 9 || characterPositions == 10)

           r += 1;

  

   //don't allow rabbit to slip past the starting line

   if (r<1)

       r =1;

   else if (r > finish) //allow program to stop running in the case of the rabbit surpasses finish line

       r = finish;

  

   }

  

   public static void turtleRace() {

       characterPositions = (int)(1 + Math.random() * 10);

       int turtlePosition [] = {3, 6};

       if (characterPositions == 1 || characterPositions == 2 || characterPositions == 3 || characterPositions == 4|| characterPositions == 5)

           t += 3;

       else if (characterPositions == 6 || characterPositions == 7)

           t -= 6;

       else if (characterPositions == 8 || characterPositions == 9 || characterPositions == 10)

           t +=1;

      

      

       if (t<1) //don't allow turtle to slip past starting line

           t = 1;

       else if (t > finish) //allow program to stop running in the case of the turtle surpassing finish line

           t = finish;

   }

  

   public void display () {

       for (int letter = 1; letter <= finish; letter++)

           if (letter == r && letter == t)

               System.out.print("Ouch!");

          

           else if (letter == r)

               System.out.print("H");

          

           else if (letter == t)

               System.out.print("T");

           else System.out.print(' ');

       System.out.println();

          

   }}

  

  

  

}

Explanation / Answer

Ans. Remove the semicolon (;) and place at the end of the Class Name, along with this declare the object which can be of any name.

Current Code:- JavaRace;Simulation

Expected Code :- JavaRace;Simulation object = new JavaRaceSimulation();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote