Jeroo Lab 4: Loops

Create 2 methods that each use a loop: pickARow and findWater as described below. Create a main program that will work on any of the ring islands to make a Jeroo pick all of the flowers and stop.

Start with this main method to test your code:

Use this code for the main method to test your methods.

//************************************************
//Precondition: There is a square island with flowers on each side
//Postcondition: All flowers on the ring island have been picked
//************************************************
method main()
{
   Jeroo circuitRunner = new Jeroo();
   circuitRunner.pickARow();
   //circuitRunner.findWater();
}
      

First create and test the pickARow method, then create the findWater method and remove the comments to test it.

Problem 1: Create the Pick a Row method
     
     
     
     

Complete the code for the pickARow method and test to be sure that it works for any number of flowers in a row.

//************************************************
//Precondition: There is at least 1 flower directly ahead of the Jeroo
//Postcondition: All flowers that were directly ahead of the Jeroo have been picked
//************************************************
method pickARow()
{



}
       
       
   
       

Problem2: Find Water (create your own island)
 


before


after

Write the code for a findWater() method. Whatever direction the Jeroo is facing, it will keep moving forward until it encounters water. When water is found, the Jeroo turns right. Test your program thoroughly.

//********************************************
//Precondition: There is at least one clear space 
//   in front of the Jeroo and no obstacles 
//   (nets or other Jeroos) 
//   in its path
//Post condition: The Jeroo stops when it is 
//   facing the water and then turns to its right.
//*******************************************

method findWater()
{









}


before

after

Problem 3: Circle the Ring: Combine Pick a Row and Find water. (uses islands: ring1 and ring2)
 

The Ring Islands each have rows of flowers along each outer shore of the island. Write a program that uses the pickARow and findWater methods to send a Jeroo from a starting location at (0,0) all the way around the island, picking each row of flowers as it goes.

Create a loop in the main program that will repeat the pickARow( ) and findWater( ) methods until the island has been cleared.

 Jeroo circuitRunner = new Jeroo();
 while( ____________________________________ ) {
    circuitRunner.pickARow();
    circuitRunner.findWater();
 }

If you can figure out what is true at the beginning of the program and also after pickARow and findWater are completed each time, you can easily write the condition for the circuitRunner.

The same program must work for both islands with no modifications. Save as CircleRingYourName.