Cs106a jobs and others

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.