|
GwJeroo
Projects II
Jeroo Page
Objective: to understand what two core variable types in Java (boolean and int) and to write a loop.
Project 3
-
- Create a new class in Eclipse. This class should be called
Loops101 . Delete the code that eclipse gave you and paste the code below into it
import info.gridworld.world.*;
import info.gridworld.grid.Location;
import javax.swing.JOptionPane;
public class Loops101 {
public static void main(String[] args) {
JerooWorld world = new JerooWorld();
ExtendedJeroo kim = new ExtendedJeroo();
world.add(new Location(0,0),kim);
world.show();
//a boolean variable
boolean clearLeft = kim.isClear(Jeroo.LEFT) ;
boolean clearAhead = kim.isClear(Jeroo.AHEAD) ;
System.out.println("Left is clear ? " + clearLeft);
System.out.println("Ahead is clear ? " + clearAhead);
//a variable that represents an integer
int numberOfHops =0;
while(kim.isClear(Jeroo.AHEAD)){
kim.hop();
numberOfHops++;
System.out.println("Number of hops: "+ numberOfHops);
}
}
}
Try running the code. Your job is to write a loop that will make the Jeroo circle around the outer rim of the grid. You should count how many hops it takes to go one full lap aroundd.
|