Review of conditionals and looping

1. Consider this program fragment and picture

Jeroo bob = new Jeroo();
if(bob.isNet(AHEAD))
  {
   bob.turn(RIGHT);
   bob.hop(5);
   }
  else
   {
   bob.hop();
    }

Where will bob be after this part of the program executes?

a. in the net
b. (5, 0)
c. (0, 5)
d. in the water

2. Consider this program fragment and picture

Jeroo bob = new Jeroo();
if(bob.isClear(AHEAD))
  {
   bob.turn(RIGHT);
   bob.hop(5);
   }
  else
   {
   bob.hop();
    }

Where will bob be after this part of the program executes?

a. in the net
b. (5, 0)
c. (0, 5)
d. in the water

      What mistake did the person make on #2

 

3. Consider this program fragment and picture

Jeroo bob = new Jeroo();
while(bob.isFlower(AHEAD))
  {
   bob.hop();
   bob.pick();
   }
  

Why does bob not gather all the flowers?

a. he does gather all the flowers
b. the while should be an if
c. there is not flower ahead after the
     first flower is picked
d. he lands in the water

4. Consider this program fragment and picture

Jeroo bob = new Jeroo();
if(bob.isFlower(AHEAD))
  {
   bob.pick();
   }
   else
   {
    bob.hop();
    }

How many flowers does bob pick?

a. 8
b. 7
c. 1
d. 0

What is the difference between if( ) and while ( ) ?

6. Consider this program fragment and picture

Jeroo bob = new Jeroo();
while(bob.isClear(AHEAD))
{
  if(bob.isFlower(RIGHT))
   {
    bob.pick();
    }
  bob.hop();
}

a. How many flowers will bob pick up ?

b. Will bob stop when he reaches the net?

7. Would this code have worked the same if we had done this?

while(bob.isClear(AHEAD))
{
  if(bob.isFlower(RIGHT))
   {
    bob.pick();
    bob.hop();
    }
  
}

8. Consider this program fragment and picture

Jeroo bob = new Jeroo(0,2, SOUTH);
while(bob.isWater(LEFT))
{
  
bob.hop();
  //we need something!
}

bob does not move to the end of the water.
which of these conditional should be added to the while loop

a. if(bob.isClear(RIGHT))
  {
   bob.hop();
   }

b. if(bob.isClear(RIGHT))
  {
   bob.hop(2);
   }
c. if(bob.isWater(LEFT))
    {
     bob.hop(2);
     }

  
     
9. What is the difference between the coding fragments on the right. They are part of a Jeroo method while(isClear(AHEAD))
  {
   hop();
   }
if(isClear(AHEAD))
  {
  hop();
  }
10. What is the difference between the coding fragments on the right. They are part of a Jeroo method if(isClear(AHEAD))
  {
   hop();
   }
else
  {
   plant();
   }
if(isClear(AHEAD))
  {
  hop();
  }
plant();
11. When will these conditionals be TRUE

a.
if(bob.isWater(LEFT))

b.
if(bob.hasFlower())

c. if(!bob.isClear(AHEAD))

d. if(!bob.isNet(RIGHT))