Problem 1

To start off with, I am using Eclipse and have attached my settings to get it to work with this assignment.

And now to actual run the code you need to include some things from the acm.jar file, since that is what is mainly being used to hide allot of the Java main implementations. So if you goto the the Package Explorer on the left hand side, and double click on the Package->default packages->CollectNewsPaper.java then to setup the environment for running this java file you need to goto Run->Run Configurations.. on the left options make sure that Java Applications -> New configuration is selected and then select the Project name as the Package and then tick the “include system libraries when searching for the main class” and also the “include inherited mains when searching for the main class”, then on the “main class” option, click search and find the CollectNewsPaper. Here is a image of how it should look.

Eclipse CS106A settings
Eclipse CS106A settings

Now, you should just see a robot (Karel) in the top left of the house and that is about it, we need to write the run() method for him to pick up the newspaper, so alter the code to the below.

/*
 * File: CollectNewspaperKarel.java
 * --------------------------------
 * At present, the CollectNewspaperKarel subclass does nothing.
 * Your job in the assignment is to add the necessary code to
 * instruct Karel to walk to the door of its house, pick up the
 * newspaper (represented by a beeper, of course), and then return
 * to its initial position in the upper left corner of the house.
 */
 
import stanford.karel.*;
 
public class CollectNewspaperKarel extends SuperKarel {
 
	private void getPaper()
	{
		move();
		turnRight();
		move();
		turnLeft();
		move();
		move();
	}
 
	private void pickUpPaper()
	{
		pickBeeper();
	}
 
	private void goBack()
	{
		// turn around basically
		turnRight();
		turnRight();
		move();
		move();
		move();
		turnRight();
		move();
		turnRight();
	}
 
	public void turnLeft()
	{
		turnRight();
		turnRight();
		turnRight();
	}
 
	// You fill in this part
	public void run()
	{
		getPaper();
 
		pickUpPaper();
 
		goBack();
	}
}

and then run again and if you click “start” he will go and pick up the newspaper and return back to where he started from.

I am finding this CS106A fun. In the above zip file there is the full source code for all of the parts to assignment 1, and also the assignment in a PDF file. But I shall place each part on a different post.