CSC 171
Homework assignment 5

Fall, 1998

More practice with Buggles and methods

The Buggle Bagel Ruggle Company

(Homework assignment based on one by Dr. Frank Turbak of Wellesley College.)

The buggles from Homework Assignment 2, becky, bobby, and bertie, had the foresight to copyright their Buggle Olympic Symbol. As a result, they made a killing on the use of the logo for Buggles Olympics memorabilia and merchandise. So, they decided to invest in a rug-making enterprise: The Buggle Bagel Ruggle Company, which designs and weaves rugs made by dropping bagels in interesting ways on a BuggleWorld grid.

Here is an example of a rug they created:

Picture of Buggle control panel with 'rug' of colored bagels

The buggles are great designers, but, unfortunately, they don't know much about manufacturing. It takes so long to hand-drop the bagels individually that it's impossible to make any money. Luckily for them, there is a way to automate the production of the rugs. As it turns out, the design shown above can be produced using just 4 different 3x3 grids of bagel patterns:

four 3x3 patterns

It is also helpful to realize that the rug design consists of three concentric rings of 3x3 grids, as indicated by the heavy black outines shown below (the lighter black lines demarcate the 3x3 grid patterns):

the rug again, broken into three concentric layers

Your assignment:

The problem is to come up with a way to take advantage of the rug structure to produce the rug with methods. You should be able to create the rug using a very similar technique to the one you used for the "acrobatics" assignment.

Download the hw5Buggles folder from my download directory on panther. It should contain BuggleWorld.java, Rug_BuggleWorld.java, and hw5Buggles.mcp, among other things.

Just as we needed fred to be a new kind of Buggle, called a LetterBuggle, in order to teach him to draw letters and course numbers, this assignment uses a new kind of Buggle called a RugBuggle. The RugBuggleWorld class, an extension of BuggleWorld, contains a pre-written run() method that creates a RugBuggle named "weaver" and sends it a series of requests.

In the class RugBuggle are headers for all the necessary methods. Some of these methods have their bodies filled in, while others are left blank for you to finish.

Rules:

  1. Do not change any of the code already in the file; merely add your own in the bodies of the various methods with comments that say "put your code here".
  2. Use a single RugBuggle for the entire rug (weaver, who has already been created in the file).
  3. You may not, and do not need to, use the setPosition() method. You may use any of the other Buggle methods.
  4. You should draw the colors and bagels exactly as shown in the rug.
Have fun!

Again with the Buggles? I have to go home and walk the dogs.

This assignment is a cross between the two textbooks.
  1. Start by reading and working out exercise 5 on p. 117 of Arnow & Weiss, in which you define a class named "Dog" that makes various noises (which noise is specified at the time you create the Dog). The class has three methods: bark, barkLoud, and barkSoft. Be sure to follow the design recipe for writing the methods! Also include a toString method as in the FF examples. Turn this in as a file named AWDogs1.java (with a main class named AWDogs1 that tests everything).
  2. How would Felleisen & Friedman probably address the issue of different kinds of dogs? (Hint: Felleisen & Friedman introduced abstract classes and concrete subclasses back on page 2, while Arnow & Weiss haven't discussed these issues yet.)
  3. Implement this approach to the situation, following the design recipe. Again, include toString methods in all non-abstract classes. (Hint: For purposes of this assignment, the different kinds of dogs differ only in what noise they make, which is set when a new Dog object is created. Use the super keyword of Java, discussed on pp. 40-41 of FF, to set the correct noise for each kind of Dog.) Turn this in as a file named FFDogs1.java, with a main class named FFDogs1 that tests all your examples.
  4. Type in the definition of the InteractiveIO class from the textbook, page 104, in a file named InteractiveIO.java. Note that this file has no main method, since it's not intended as a stand-alone program.
  5. Make a copy of AWDogs1.java, calling it AWDogs2.java. Add read, readi, and print methods to this file as in exercise 1, p. 125. Note that your print method may be considerably simpler than the examples in the book, because you've already written toString. Also note that readi depends on InteractiveIO, so add InteractiveIO.java to the list of source files in your project file (just as the buggles projects all include BuggleWorld.java).
  6. Try making an FFDogs2.java and adding read, readi, and print methods. What goes wrong? Try to find a way to do this anyway.

What to turn in:

  1. The version of Rug_BuggleWorld.java with all the method bodies filled in, so that when the user clicks on the "Run()" button, weaver will be created and draw a rug exactly like the one above.
  2. AWDogs1.java, exactly as described in the AW book (except that you've added toString methods).
  3. FFDogs1.java.
  4. AWDogs2.java, which is simply AWDogs1.java plus some I/O methods.
  5. FFDogs2.java, with as good a solution to the I/O methods as you can come up with. Discuss (in a Java comment) what problems, if any, you were unable to solve.

Last modified: Mon Oct 19 12:05:55 EDT 1998
Stephen Bloch / sbloch@boethius.adelphi.edu