jKarel Lab 06
Transcript of jKarel Lab 06
![Page 1: jKarel Lab 06](https://reader031.fdocuments.in/reader031/viewer/2022013111/5537c3204a79596f718b45b2/html5/thumbnails/1.jpg)
//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](https://reader031.fdocuments.in/reader031/viewer/2022013111/5537c3204a79596f718b45b2/html5/thumbnails/2.jpg)
{ 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](https://reader031.fdocuments.in/reader031/viewer/2022013111/5537c3204a79596f718b45b2/html5/thumbnails/3.jpg)
World tasks1
![Page 4: jKarel Lab 06](https://reader031.fdocuments.in/reader031/viewer/2022013111/5537c3204a79596f718b45b2/html5/thumbnails/4.jpg)
World tasks2
![Page 5: jKarel Lab 06](https://reader031.fdocuments.in/reader031/viewer/2022013111/5537c3204a79596f718b45b2/html5/thumbnails/5.jpg)
World tasks 3