6
//Name David Willmore Date 8 Dec. 2011 import edu.pace.World; import edu.pace.Robot; import javax.swing.JOptionPane; public class Lab06 { public static void main(String[] args) { String filename = JOptionPane.showInputDialog("What robot world?"); World.readWorld(filename); World.setSize(10, 10); World.setSpeed(10); task_01(); //go to the end of the row of beepers task_02(); //go to the beeper task_03(); //go to the wall task_04(); //go to the wall, pick up all the beepers (max one per pile) task_05(); //go to the wall, pick up all the beepers task_06(); //go to the end of the row of beepers, there is one gap } public static void task_01() { //go to the end of the row of beepers Robot temp = new Robot(1, 1, World.EAST, 0); while(temp.nextToABeeper()) { temp.move(); } } public static void task_02() { //go to the beeper Robot temp = new Robot(1, 2, World.EAST, 0); for(int k=0; k<10; k++) { if(temp.nextToABeeper()) { } else { temp.move(); } } } public static void task_03() { //go to the wall Robot temp = new Robot(1, 3, World.EAST, 0); while(temp.frontIsClear())

jKarel Lab 06

  • Upload
    david-w

  • View
    232

  • Download
    7

Embed Size (px)

Citation preview

Page 1: jKarel  Lab 06

//Name David Willmore Date 8 Dec. 2011 import edu.pace.World; import edu.pace.Robot; import javax.swing.JOptionPane; public class Lab06 { public static void main(String[] args) { String filename = JOptionPane.showInputDialog("What robot world?"); World.readWorld(filename); World.setSize(10, 10); World.setSpeed(10); task_01(); //go to the end of the row of beepers task_02(); //go to the beeper task_03(); //go to the wall task_04(); //go to the wall, pick up all the beepers (max one per pile) task_05(); //go to the wall, pick up all the beepers task_06(); //go to the end of the row of beepers, there is one gap } public static void task_01() { //go to the end of the row of beepers Robot temp = new Robot(1, 1, World.EAST, 0); while(temp.nextToABeeper()) { temp.move(); } } public static void task_02() { //go to the beeper Robot temp = new Robot(1, 2, World.EAST, 0); for(int k=0; k<10; k++) { if(temp.nextToABeeper()) { } else { temp.move(); } } } public static void task_03() { //go to the wall Robot temp = new Robot(1, 3, World.EAST, 0); while(temp.frontIsClear()) { temp.move(); } // while } // task_03 public static void task_04() { //go to the wall, pick up all the beepers (max one per pile) Robot temp = new Robot(1, 4, World.EAST, 0); while(temp.frontIsClear()) if(temp.nextToABeeper())

Page 2: jKarel  Lab 06

{ temp.pickBeeper(); temp.move(); } else { temp.move(); } } public static void task_05() { //go to the wall, pick up all the beepers Robot temp = new Robot(1, 5, World.EAST, 0); while(temp.frontIsClear()) { if(temp.nextToABeeper()) { temp.pickBeeper(); } else { temp.move(); } } } public static void task_06() { //go to the end of the row of beepers, there is one gap Robot temp = new Robot(1, 6, World.EAST, 0); while(temp.frontIsClear()) if(temp.nextToABeeper()) { temp.move(); temp.move(); } else { } } }

Page 3: jKarel  Lab 06

World tasks1

Page 4: jKarel  Lab 06

World tasks2

Page 5: jKarel  Lab 06

World tasks 3