Cs106s is the number of a Stanford course called programming methodology. This course is intended for beginners who use Java. Course resources are available. I decided to paste the attached homework here. If you have any mistakes or omissions, you are welcome to correct them.
Assignment 1
Problem #1
This is a simple question about moving Karel. The problem is simple: Move Karel to the "newspaper" outside the box, pick it up, and return to the original place. The Code is as follows:
Import Stanford. Karel .*;
Public class collectnewspaperkarel extends superkarel {
Public void run (){
Move ();
Move ();
Turnright ();
Move ();
Turnleft ();
Move ();
Pickbeeper ();
Turnleft ();
Turnleft ();
Move ();
Move ();
Move ();
Turnright ();
Move ();
}
}
Problem #2
This problem is also very simple, that is, Karel is required to fill the beeper in every four columns in the graph (there are already some parts that cannot be repeated), and the starting position is ).
Import Stanford. Karel .*;
Public class stonemasonkarel extends superkarel {
Public void run (){
Repair ();
Comeback ();
While (frontisclear ()){
For (INT I = 0; I <4; I ++ ){
Move ();
}
Repair ();
Comeback ();
}
}
Private void repair (){
Turnleft ();
While (frontisclear ()){
If (nobeeperspresent ()){
Putbeeper ();
}
Move ();
}
If (nobeeperspresent ()){
Putbeeper ();
}
}
Private void comeback (){
Turnleft ();
Turnleft ();
While (frontisclear ()){
Move ();
}
Turnleft ();
}
}
Cs106a jobs and others