RPAD- Getting Started with Eclipse & Karel

First, solve the problem. Then, write the code.
– John Johnson



– Warm up

– Karel and turning right.

Today’s Work

Choose a partner. You need to be sitting next to each other, both on computers. You’ll work on one computer today, but both computer’s next time.

You’ll need to download Stanford Eclipse for Mac (mirror), and follow the directions below.

Eclipse is the Integrated Development Environment (IDE) we’ll be using both for Karel and for the Lego NXT Robots. Through the use of plugins, it can be used to program in a variety of languages for a variety of different purposes. Being both free and open source, Eclipse is a great tool for education. While we used Lightbot as a Robot Simulation and programming game, it wasn’t really one. Karel is much better for that, however, Lightbot is a bit more gentle way to introduce programming than going directly to Karel.

When Stanford Eclipse finishes downloading, drag the Eclipse folder from your downloads folder to the desktop. It’s a self contained program, and  (on the mac at least) shouldn’t require any sort of lengthy install process.

Once you open Eclipse, download the Assignment1 folder. That link is going to pop up a page with a million things, ignore them. Instead, in the top left, below where it says Assignment1.zip click File, a choose Download at the bottom of the drop down menu.

Once you’ve downloaded the Assignment1 folder, drag it to your desktop before importing it into the workspace. The icon on the left is the Import Project button, and is what your looking for. You can find it in the overhead toolbar. This will copy a project folder, in this case Assignment1, into the Eclipse workspace.

If you haven’t already, click the Import Project button and select the Assignment1 folder. This should open the Package Explorer, and you should see Assignment1 there.

Click on the small grey arrow next to Assignment1. You should see a couple things drop down, including (default package) with its own grey arrow. Click on it.

The first one to work on is CollectNewspaperKarel.Java

Double click on it (NOT the arrow this time!). This should open a document with text in the center of the IDE. You should see a large chunk of green text, like in the example below. If you don’t see all that green text, you might need to click the little plus sign near the top of the window (notice where the red arrow is pointing).

You’ll write your coding in the empty space toward the bottom, where the red arrow is pointing. But how do you know what to code?

Click the little running man in the overhead toolbar. This will allow you to run the program. I know you don’t have any coding yet, that’s alright. Just run it. You’ll be able to see the environment your navigating Karel through.

You’ll see Karel and his two room home, complete with both a front and back entry. You’ll need to navigate him to the newspaper (represented as a beeper) that’s been delivered to his front door, pick it up, and return inside. Before you start inputting commands, you’ll need to start with the command public void run() {

Try inputing the example below:

Once you’ve typed in the code, go ahead and run the program (click the running man), and click the Start Program when the Java Applet pops up.

How’d that go?

Maybe everything didn’t quite workout as you thought it would.

A window with an error message should have popped up.

Unluckily, Karel doesn’t understand iteration. Since Karel doesn’t understand iteration, this is classified as a Syntax Error. That is, essentially, an error where the coding itself is the problem. It could be also be caused by using the wrong word, a misspelling, a typo, a lower case letter where a capital should be, or even just a missing semicolon. You’ll have to type out commands multiple times instead of just dropping the value in the parenthesis.

Lets try again with code below, go ahead and run the program, and click the Start Program when the Java Applet pops up.

As you probably guessed, the code above didn’t quite work. If you followed the code above, you received another error, but this time, not until actually trying to Start Program in the Java Applet that pops up.

This type of error is called a logic error. That is, the program technically worked just fine, as there is no error in the actual code, but the result of the code won’t produce the desired effect. The logic you applied to solve the program wasn’t correct, so you’ll need a different series of commands.

At this point, you can probably figure out what to change to solve this. The goal is for Karel to retrieve the “newspaper” from his doorstep. That is, go to the newspaper, pick it up, and return inside.

Come up with two different working solutions. Screenshot the code for each, and upload the images to your blog.

When you’ve completed the program CollectNewspaperKarel, see if you can complete the other three programs. For the other three programs, you only need one solution for now, and we’ll work on a more efficient solution later on.

Next Class: Loops, Functions, Subclasses, and Conditionals

This entry was posted in RPaD.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s