BuggleWorld.java
,
CSC171_BuggleWorld.java
,
and hw4Buggles.mcp
, among other things.
In CSC171_BuggleWorld.java
is a class named
LetterBuggle
,
containing the header for a method named writeC
that takes a Color parameter. Fill in the definition of this method
so that whenever fred is sent this message, he will draw a
letter C (three blocks wide by five high) in the specified color,
as shown:
Rules:
writeC
method.
setPosition
or
setHeading
methods. Assume that fred is at position (1,1),
facing EAST, before he is told to writeC
.
setPosition
or setHeading
to do this (but brushUp()
and brushDown()
are OK).
letter_color
parameter before painting anything.
Big deal, you say: betty knew how to draw a C two weeks ago. But watch this:
open the CSC171_BuggleWorld.java
file,
find the run()
method,
and add just after fred.writeC(red);
the additional statement
fred.writeC(green);
. If you've done everything according to the
above rules, this one additional line should produce a second C, in green,
properly positioned to the right of the first one.
writeS
, write1
, and
write7
to the LetterBuggle
class. Test
these by replacing the writeC
calls in the run()
method with each of these methods in turn.
Next, modify the program so that it writes "CSC171" with each letter
in a different color. You should be able to do this by adding only a few lines
to the run()
method.
Fred is so excited by being able to spell the name of the course that he wants
to be able to do it any time he likes. Write another method named CSC171
which writes "CSC171" with each letter in a different color.
Finally, let's give Fred more opportunity to practice his writing: we'll have him write "CSC171" along the bottom of the Buggle grid, then again sideways along the right-hand edge of the screen (moving up), again upside-down along the top of the grid, and one more time sideways along the left side, ending up where he started. Note that at each corner Fred will have to move a few squares and change directions before starting his next CSC171; this is a good opportunity for another method.
CSC171_BuggleWorld.java
containing the
writeC
, writeS
, write1
, write7
,
and CSC171
methods, as well as whatever code you wrote so Fred could
do the acrobatic tricks described in the above paragraph when you hit the "Run"
button.
allNovels
, which returns true or false to indicate whether
the stack consists entirely of Novels;
containsANovel
, which returns true or false to indicate
whether the stack contains at least one Novel; and
countNovels
, which returns an int
indicating
how many Novels were in the stack.
BookPiles.java
, containing
definitions of the classes and a main program to test them. In
particular, for each of the methods and constructors, you are to write
boolean onlyOnions () {in the book)
Stephen Bloch / sbloch@boethius.adelphi.edu