CS111, Wellesley College, Fall 2006

Lab 2

Wednesday/Thursday, September 13/14, 2006


Java Execution Model and Methods

Total checkmarks:

Today's agenda:


Go to the CS111 download directory using the cs111d account on puma, and download the lab2_programs folder to your desktop.

Buggles and BuggleWorld

Exercise 1: JEM

Draw JEM for the following example:


Exercise 2: Welcome to ChecksWorld!!!

Open ChecksSimple.java in DrJava.

What picture does ChecksSimple.java produce?

Run the program to see the answer.

Click here for the answer


For all the Checkerboard tasks below, you will be creating new java files from scratch. However, the HTML files are provided for you.

Task 1 -- Drawing a pattern using Methods

Create a new file called ChecksMethod.java in DrJava. Save it in your lab2_programs folder.

Task 2 -- Drawing a checkerboard using Methods

Now create a new file called Checksboard.java to solve this task.

Checksboard.java requires a 5x5 grid in BuggleWorld. You need a method called init() to create the correct size grid in BuggleWorld (much like we did last week with the 13x13 grid in Cs.java). Take a look at Hi.java (included in the lab2_programs folder) as a refresher on how to use the init() method.

In the file Checksboard.java create a new instance of the class CheckerBuggle.

Then add more methods to the class CheckerBuggle and invoke some of these methods in Checksboard.java on the CheckerBuggle that you have created.

All the drawing and most of the moving must be done in methods of the class CheckerBuggle, not in run(). In this exercise and in the rest of the lab the method run() must be very short: just creating a new buggle and a few (between one and five) method invocations. If you write the program this way, it will be easier to reuse the methods from one exercise in another.

In the end of the program the buggle must be positioned as shown below. However, it may have any color (not white, as on the picture).


Task 3 -- Drawing a more complex checkerboard (using more Methods...).

Create a new file called BigChecksboard.java, with a 15x15 grid in BuggleWorld and a CheckerBuggle class.

 

Write BigChecksboard.java to solve the problem:

 

Task 4 -- And even bigger and fancier checkerboard (using more Methods...).

Create a new file called SuperBigChecksboard.java, with a 45x45 grid in BuggleWorld and a CheckerBuggle class. SuperBigChecksboard.java should create this picture:

 

Task 5

Create a new file called FlippedSuperBigChecksboard.java with a 45x45 grid to solve this problem: