标签:
1.common errors(OBOB)
2.comment 注释
/* */ 段注释
// 行注释
3.decomposition “Top Down design”
分解 自顶向下设计
4.doublebeeper
1 import stanford.karel.*; 2 public class DoubleBeeper extends Karel{ 3 int num=0; 4 public void run(){ 5 move(); 6 doublebeeper(); 7 moveback(); 8 } 9 public void moveback(){ 10 turnAround(); 11 move(); 12 turnAround(); 13 } 14 public void turnAround(){ 15 turnLeft(); 16 turnLeft(); 17 } 18 public void doublebeeper(){ 19 while(beepersPresent()){ 20 pickBeeper(); 21 num++; 22 } 23 for(int i=0;i<2*num;i++){ 24 putBeeper(); 25 } 26 } 27 }
5.cleanBeeper
1 import stanford.karel.*; 2 public class CleanBeeper extends Karel{ 3 public void run(){ 4 cleanRowBeeper(); 5 while(leftIsClear()){ 6 rightGoTop(); 7 cleanRowBeeper(); 8 if(rightIsClear()){ 9 leftGoTop(); 10 cleanRowBeeper(); 11 } 12 else{ 13 turnAround(); 14 } 15 } 16 } 17 public void cleanRowBeeper(){ 18 while(frontIsClear()){ 19 if(beepersPresent()) 20 pickBeeper(); 21 move(); 22 } 23 if(beepersPresent()) 24 pickBeeper(); 25 } 26 public void rightGoTop(){ 27 turnLeft(); 28 move(); 29 turnLeft(); 30 } 31 public void leftGoTop(){ 32 turnRight(); 33 move(); 34 turnRight(); 35 } 36 public void turnRight(){ 37 turnLeft(); 38 turnLeft(); 39 turnLeft(); 40 } 41 public void turnAround(){ 42 turnLeft(); 43 turnLeft(); 44 } 45 }
标签:
原文地址:http://www.cnblogs.com/ftdwlei/p/4454905.html