Computer Programming

  • Uploaded by: Bank
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Computer Programming as PDF for free.

More details

  • Words: 382
  • Pages: 17
1)

Code import stanford.karel.Karel;

/** * */

/** * @author student *

*/ public class AngkorKarel extends Karel {

/** * @param args */ public void run() { claimUp(); longJump(); move(); claimDown();

}

public void claimUp() { for (int i = 0; i < 3; i++) { turnLeft(); move(); turnRight(); move(); } }

public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }

public void longJump() { move(); turnAround(); turnAround(); move(); }

public void turnAround() { turnLeft(); turnLeft(); }

public void claimDown() { for (int i = 0; i < 3; i++) { turnRight();

move(); turnLeft(); move(); } }

} ขั้นตอนการทำางาน

2)

Code import stanford.karel.Karel;

/** * */

/** * @author student * */ public class CambodiaKarel extends Karel {

/** * @param args */

public void run() { while (frontIsClear()) { for (int i = 0; i < 3; i++) { move();

} highJump(); }

}

public void highJump() { turnLeft(); move(); turnRight(); move(); turnRight(); move(); turnLeft(); }

public void turnRight() {

turnLeft(); turnLeft(); turnLeft(); }

} ขั้นตอนการทำางาน

3)

Code import stanford.karel.Karel;

/** * */

/** * @author student * */ public class RabsaraKarel extends Karel {

/** * @param args */

public void run() { highJump(); move(); turnRight(); while (frontIsClear()) { move(); } turnLeft(); putBeeper(); highJump();

}

public void highJump() { for (int i = 0; i < 4; i++) { turnLeft(); move(); turnRight(); move(); } }

public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }

} ขันตอนการทำางาน

4)

Code import stanford.karel.Karel;

/** * */

/** * @author student * */ public class BarayKarel extends Karel {

/** * @param args

*/ public void run() { for (int i = 0; i < 5; i++) { fillPothole(); }

}

public void fillPothole() { move(); turnRight(); move(); move(); putBeeper(); turnAround(); move(); move(); turnRight(); move(); }

public void turnRight() {

turnLeft(); turnLeft(); turnLeft(); }

public void turnAround() { turnLeft(); turnLeft(); }

} ขั้นตอนการทำางาน

5)

Code import stanford.karel.Karel;

/** * */

/** * @author student * */

public class SiharnuKarel extends Karel {

/** * @param args */ public void run() { for (int i = 0; i < 13; i++) { claimUp();

} move(); move(); pickBeeper();

}

public void claimUp() { move(); putBeeper(); turnAround(); move(); turnRight();

move(); turnRight();

}

public void turnRight() { turnLeft(); turnLeft(); turnLeft(); }

public void turnAround() { turnLeft(); turnLeft(); }

}

Related Documents


More Documents from "Bank"

Aim Star
June 2020 19
June 2020 18
June 2020 17