|
Lab 2
|
Today's agenda:
Go to the CS111 download directory using the
cs111d account on puma, and download the
lab2_programs folder to your desktop.
Open ChecksSimple.java in DrJava.
What picture does ChecksSimple.java produce?
Task 1
Create a new file called ChecksMethod.java in DrJava. Save it in
your lab2_programs folder.
ChecksMethod.java must define the class called ChecksMethod
(like you create the Cs class last week in Cs.java)
run method should go inside the ChecksMethod class
CheckerBuggle that extends the Buggle class
(this class definition can go below the ChecksMethod class definition)
CheckerBuggle class, write
a method which draws the same picture as the
program in ChecksSimple.java does. CheckerBuggle (in the ChecksMethod.java file)
write the header of the method that will draw the picture (is it
public or private? Is it void or does it return any value?). Think of
a good name for the method. Put the opening and closing braces { and
} for the body of the method. Do not yet write the code for the body.
ChecksMethod.java, create a new
CheckerBuggle in the method run() and invoke the new
method (the one that you are writing) on this
CheckerBuggle. Compile and run the program. Since
there is nothing in the body of the method yet, you should only see
the new buggle on the applet, but no drawing.
Task 2
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
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
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: