Graphic by Keith Ohlfs

CS111, Wellesley College, Fall 1997

Prelab #6
[CS111 Home Page] [Syllabus] [Students] [Lecture Notes] [Assignments] [Programs] [Documentation] [Software Installation] [FAQ] [CS Dept.] [CWIS]

CS111 Prelab #6: Buggles

Due Date: Before lab, October 20 or 21.

In lecture you were introduced to Buggleworld. In this world you can create "Buggles" that can move in different directions and draw onto their grid world. You saw how to write a Java method to have a Buggle draw a square. In this prelab you will write Java methods to have a Buggle draw a "snake" that is in the shape of the letter "S".

1) First, download the folder, Buggles, from the download directory for cs111 on Nike. This folder contains lots of java source files, html files, class files and one project file. Make sure all the icons are displaying the proper images (e.g. a coffee cup on the class files). If they are not, download the fetch preferences again and try again.

2) Open the project window and double click on "MyBuggleWorld2.java". This is the version of Buggleworld in which Buggles can draw squares. Change the name of the class to MyBuggleWorld3. Choose "Save As..." from the file menu and save this file as "MyBuggleWorld3.java". Double click on "MyBuggleWorld.html". Change the name of the class that it invokes to "MyBuggleWorld3.class". Choose "Save As..." and save this file as MyBuggleWorld3.html. Choose "Bring Up to Date", and use the Applet Viewer to look at the html file, "MyBuggleWorld3.html". When the applet appears, you can click on the "Run" button to see the buggles draw some stuff.

3) Now add two new methods to the MyBuggle2 class that appears at the bottom of the MyBuggleWorld3.java file. One method should be called "forward8()" and should move the Buggle forward 8 squares. Make sure to use the forward4() method inside this new method. The second method should be called "drawSnake()". This method should make use of the methods forward8, forward4, left and right. It should draw the following figure when the buggle starts in the lower lefthand corner of the grid (which is the default starting position of the Buggle).

4) Change the code inside the "run()" method of MyBuggleWorld3. First, delete all of the old code, except for the first two lines:
public void run () {
MyBuggle2 becky = new MyBuggle2();
becky.setColor(Color.red);
}
Now, add one more statement to invoke the snake method, and have becky draw the snake. If you are unsure of how to do this, look at MyBuggleWorld2.java and see how the method to draw a square is invoked.

5) Finally, bring your project up to date, and use the applet viewer to view "MyBuggleWorld3.html". Click on the "Run" button to see becky draw the snake.

Turning in Prelab 6

When you are finished. Save three files (MyBuggleWorld3.java, MyBuggleWorld3.html and MyBuggleWorld3.class) in a folder named "username_prelab6", where username is your username. Do not include the Buggleworld.proj file. Upload this folder into the lab6 drop folder on Nike.