CSC 171
Homework assignment 4

Fall, 1998

In class:

Download the hw4Buggles folder from my download directory on panther. It should contain 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:

If you've done all this correctly, you should be able to hit the "Run()" button and see fred draw a C.

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.

To be done outside class:

Method in their Buggleness

Add three more methods named 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.

To be turned in:

Homework 4a: Fred's Excellent Adventure

You are to turn in the version of 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.

Homework 4b: Enough with the Buggles, already; let's read a book

This assignment will more closely resemble something out of the Felleisen & Friedman book. You are to design a datatype to model a pile of books stacked on the floor. There should be at least three different kinds of books, e.g. Novel, Textbook, etc. Write appropriate constructors for each class. In addition, write three methods for this datatype: All this should be in a Java Application named BookPiles.java, with toString() methods in all the non-abstract classes as illustrated in my Felleisen & Friedman Folder. Choose several test cases and include them in the main method of your program.

What to turn in for BookPiles

  1. A class diagram showing how all the classes you defined relate to one another (this may be drawn and turned in on paper, or turned in by email -- your choice).
  2. A Java source file, 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
    1. A "contract" showing what kind of information the method or constructor expects to be given, and what kind of information it promises to produce (this should be in a Java comment at the beginning of the method)
    2. A list of several examples of how the method or constructor could be used, along with the "correct" answer you would expect the method or constructor to produce (also in a Java comment, just after the contract)
    3. The "head" of the method or constructor (corresponding to
       boolean onlyOnions () { 
      in the book)
    4. The "body" of the method or constructor
    5. Several lines in the main program that actually try the method on the examples you listed above, so that I can see that they produce the correct answer.


Last modified: Tue Oct 27 09:07:34 EST 1998

Stephen Bloch / sbloch@boethius.adelphi.edu