Mr.MAMPAN SANGSA ID: 50052535
1)
Code import stanford.karel.Karel;
/** * */
/** * @author 50052535
* */ public class SeasideKarel extends Karel {
/** * @param args */ public void run() { turnLeft(); putBeeper(); while (frontIsClear()) { move(); if (noBeepersPresent()) { putBeeper(); } } turnRight(); for (int i = 0; i < 4; i++) { move(); } turnRight(); putBeeper();
while (frontIsClear()) { move(); if (noBeepersPresent()) { putBeeper(); } } turnLeft(); for (int i = 0; i < 4; i++) { move(); } turnLeft(); putBeeper(); while (frontIsClear()) { move(); if (noBeepersPresent()) { putBeeper(); } } turnRight(); for (int i = 0; i < 4; i++) { move(); }
turnRight(); while (frontIsClear()) { move(); if (noBeepersPresent()) { putBeeper(); } } turnLeft(); }
public void turnRight() { turnLeft(); turnLeft(); turnLeft();
} } ขั้นตอนต่อไป
2)
โค้ด import stanford.karel.Karel;
/** * */
/**
* @author 50052535 * */ public class RuknongKarel extends Karel {
/** * @param args */ public void run() { move(); for (int i = 0; i < 5; i++) { pickBeeper(); fillPothole(); }
}
public void fillPothole() { move(); turnRight(); move(); putBeeper();
turnAround(); move(); turnRight(); move();
}
public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }
public void turnAround() { turnLeft(); turnLeft(); }
} ขั้นตอนต่อไป
3)
โค้ด import stanford.karel.Karel;
/** * */
/** * @author 50052535 * */ public class BlueKarel extends Karel {
/** * @param args */ public void run() { while (frontIsClear()) { move(); if (noBeepersPresent()) { if (beepersInBag()) { putBeeper(); } } if (frontIsBlocked()) { turnLeft(); }
} } } ขั้นตอนต่อไป
4)
Code import stanford.karel.Karel;
/** * */
/** * @author 50052535 * */ public class SanookKarel extends Karel {
/** * @param args */ public void run() { for (int i = 0; i < 7; i++) { claimUp(); } move(); move(); move(); for (int i = 0; i < 5; i++) { jumpUp(); } putBeeper(); move(); for (int i = 0; i < 5; i++) { jumpDown(); } move(); move();
for (int i = 0; i < 7; i++) { claimDown(); } move(); move(); }
public void claimUp() { while (frontIsClear()) { move(); } putBeeper(); turnAround(); move(); turnRight(); move(); turnRight(); }
public void turnRight() { turnLeft();
turnLeft(); turnLeft(); }
public void turnAround() { turnLeft(); turnLeft(); }
public void jumpUp() { turnLeft(); move(); turnRight(); move(); }
public void jumpDown() { turnRight(); move(); turnLeft(); move();
}
public void claimDown() { turnRight(); move(); turnRight(); move(); putBeeper(); turnAround(); move(); } } ขั้นตอนต่อไป
5)
โค้ด import stanford.karel.Karel;
/** * */
/**
* @author 50052535 * */ public class HappyKarel extends Karel {
/** * @param args */ public void run() { for (int i = 0; i < 28; i++) { move(); claimUp(); claimDown(); } }
public void claimUp() { if (frontIsBlocked()) { if (rightIsBlocked()) { turnLeft(); }
} }
public void claimDown() { if (rightIsClear()) { putBeeper(); move(); putBeeper(); turnRight(); move(); putBeeper(); turnRight(); move(); putBeeper(); }
}
public void turnRight() { turnLeft(); turnLeft();
turnLeft(); }
} ขั้นต่อนต่อไป