0% found this document useful (0 votes)
9 views

kernel programming with java

The document outlines the programming assignments and grading criteria for CS106A, including details about Karel the Robot programming. It provides information on late days, section signups, and introduces programming concepts such as loops and conditionals. Additionally, it includes sample Karel programs and explanations of their components.

Uploaded by

marybellesuez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

kernel programming with java

The document outlines the programming assignments and grading criteria for CS106A, including details about Karel the Robot programming. It provides information on late days, section signups, and introduces programming concepts such as loops and conditionals. Additionally, it includes sample Karel programs and explanations of their components.

Uploaded by

marybellesuez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Programming Karel the Robot

Announcements
● Four Handouts Today:
● Downloading Eclipse
● Running Karel Programs in Eclipse
● Programming Assignment #1
● Submitting Programming Assignments
● Programming Assignment #1 Out:
● Karel the Robot: Due Friday, January 20 at
3:15 PM
● Email: Due Sunday, January 22 at 11:59PM
The CS106A Grading Scale
++
+
✓+

✓-
-
--
0
Assignment Grading
● You will receive two scores: a functionality
score and a style score.
● The functionality score is based on how
well your program works.
● Does it work correctly in the sample worlds?
● Does it work correctly in custom test worlds?
● The style score is based on how well your
program is written.
● We'll cover elements of good style throughout
this course.
Late Days
● Everyone has two free “late days” to use
as you see fit.
● A “late day” is an automatic extension for
one class period (Monday to Wednesday,
Wednesday to Friday, or Friday to
Monday).
● If you need an extension beyond late
days, please talk to Jeremy.
Section Signups
● Section signups open tomorrow at 5PM
and close Sunday at 5PM.
● Sign up for section at
http://cs198.stanford.edu/section
● Link available on the CS106A course
website.
Our Very First Karel Program Revisited
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft();
move();
turnLeft();
turnLeft();
turnLeft();
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft();
move();
turnLeft();
turnLeft();
turnLeft();
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft();
move(); This piece of the
turnLeft(); program's source code
turnLeft(); is called a method.
turnLeft();
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move(); This line of code gives
turnLeft(); the name of the method
move(); (here, run)
turnLeft();
turnLeft();
turnLeft();
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft(); The inside of the method
move(); is is called the body of
turnLeft(); the method and tells
turnLeft(); Karel how to execute the
turnLeft(); method.
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft();
move(); This part of the program is
turnLeft(); called a class definition.
turnLeft(); We'll discuss classes later
turnLeft(); this quarter.
move();
putBeeper();
move();
}
}
import stanford.karel.*;

public class OurKarelProgram extends Karel {


public void run() {
move();
pickBeeper();
move();
turnLeft();
move();
This is called an import
turnLeft();
statement. Again, we will
turnLeft();
turnLeft(); discuss this later in the quarter.
move();
putBeeper();
move();
}
}
Improving our Program
The for loop
for (int i = 0; i < N; i++) {
… statements to repeat N times …
}
The while loop
while (condition) {
… statements to repeat when condition holds …
}

Some of Karel's Conditions:

frontIsClear()
frontIsBlocked()
beepersPresent()
beepersInBag()
facingNorth()
facingSouth()

See the Karel reader (Page 18) for more details.


while (condition) {
… statements to repeat when condition holds …
}

Some of Karel's Conditions:

frontIsClear()
frontIsBlocked()
beepersPresent()
beepersInBag()
facingNorth()
facingSouth()

See the Karel reader (Page 18) for more details.


The if statement
if (condition) {
… statements to repeat if condition holds …
}

if (condition) {
… statements to repeat if condition holds …
} else {
… statements to repeat if condition doesn't hold …
}

You might also like