1.common Errors (Obob)
2.comment comments
/* */Paragraph Notes
Line Comment
3.decomposition "Top Down Design"
Decomposition from top to bottom design
4.doublebeeper
1 ImportStanford.karel.*;2 Public classDoublebeeperextendskarel{3 intNum=0;4 Public voidrun () {5 move ();6 Doublebeeper ();7 Moveback ();8 }9 Public voidMoveback () {Ten turnaround (); One move (); A turnaround (); - } - Public voidturnaround () { the turnleft (); - turnleft (); - } - Public voidDoublebeeper () { + while(Beeperspresent ()) { - Pickbeeper (); +num++; A } at for(inti=0;i<2*num;i++){ - Putbeeper (); - } - } -}
5.cleanBeeper
1 ImportStanford.karel.*;2 Public classCleanbeeperextendskarel{3 Public voidrun () {4 Cleanrowbeeper ();5 while(Leftisclear ()) {6 rightgotop ();7 Cleanrowbeeper ();8 if(Rightisclear ()) {9 leftgotop ();Ten Cleanrowbeeper (); One } A Else{ - turnaround (); - } the } - } - Public voidCleanrowbeeper () { - while(Frontisclear ()) { + if(Beeperspresent ()) - Pickbeeper (); + move (); A } at if(Beeperspresent ()) - Pickbeeper (); - } - Public voidRightgotop () { - turnleft (); - move (); in turnleft (); - } to Public voidLeftgotop () { + turnright (); - move (); the turnright (); * } $ Public voidTurnRight () {Panax Notoginseng turnleft (); - turnleft (); the turnleft (); + } A Public voidturnaround () { the turnleft (); + turnleft (); - } $}
Stanford University: Programming Methodology Lesson Three