Graphic by Keith Ohlfs
CS111, Wellesley College, Fall 2001

Problem Set 2

Due: Tuesday, September 25 by 11 pm

[CS111 Home Page] [Syllabus] [Assignments] [Documentation] [FAQ] [CS Dept.] [CWIS]

About this Problem Set

This problem set is intended to help you understand how Java works and to give you practice using, designing, and writing methods. To get the code for this assignment, connect to nike via Fetch and download the folder ps2_programs from the directory /usr/users/cs111/download.

How to turn in this Problem Set

Submit the entire ps2_programs folder to your drop folder on the cs111 server. Before submitting your work, make sure that all the files have been saved and the project compiles and runs as it should. After submitting your work, make sure to doublecheck that all the files have been uploaded correctly. If you need directions on how to submit your work or how to check whether the submission was successful, please click here. Please make sure to keep a copy of your work, either on a zip disk, or in your private directory (or, to play it safe, both).


Task 1: Buggle Name Writing using Methods

It is possible to use methods to expand the capabilities of the buggle name writing program from problem set 1. For example, using a larger grid, but fewer actual lines of code, a buggle can write the word "JAVA" multiple times, around the perimeter of the grid, as shown below:

Your assignment:

Using methods, create the above grid. The file Writing2.java contains Java code which creates a larger grid and defines a LetterBuggle, a new class of objects which extends the Buggle class. A new LetterBuggle named ellie has also been created for you, along with two LetterBuggle methods; writeName, and writeJ, as shown below:

// write the word "JAVA" around the perimeter of the grid
 
public void run () {
  LetterBuggle ellie = new LetterBuggle();
  ellie.writeName();
 
  // add your code here
  // statements which will write the word "JAVA" around the perimeter of the grid
 
}
 
 
class LetterBuggle extends Buggle {
 
  // write the word "JAVA", in the appropriately colored letters, by setting the color,
  // and then by invoking methods for writing the individual letters
  public void writeName () {
 
 
    // fill in with statements which will position this Buggle correctly to start writing 
 
 
    this.setColor(Color.blue);
    this.writeJ();    // write the first "J", in blue
 
    // add your code here
    // statements which will write the "A V A" in the correct colors
  }
 
 
  //write the letter "J"
  public void writeJ() {
    this.left(); // face NORTH
    this.forward(); // draw hook in lower left of "J"

    // add your code here
    // the rest of the statements for writing a "J"
 
  }
 
  // add your code here
  // methods for writing the other letters in the word
 
}
Perform the following steps to solve the problem: You must conform to the following rules:
  1. You may not invoke the "setPosition" or "setHeading" methods.
  2. You should use the methods "brushUp" and "brushDown" where appropriate.
  3. Each letter except "V" should fit in a 4x5 grid, and should be separated from the next letter by one blank space.
  4. The letter "V should occupy a 3x5 grid as shown.
  5. Ellie must draw the letters in the appropriate colors (use "setColor" to change colors).
  6. Ellie must end up in the position shown above, facing the correct direction (EAST).
  7. Use methods to solve the problem.

Task 2: The Buggle Bagel Ruggle Company


Important note: Before you begin working the second task, make sure to close the project that you were using for the first task by choosing Close from the File menu to close . Then double-click on the RugWorld.mcp icon to open the second project.

Alternatively, to be on the safe side (i.e. to make sure that you are not running the code from the previous task instead of the new one), you might want to quit CodeWarrior entirely and reopen it for the new project. To do this

  1. quit CodeWarrior (File -> Quit),
  2. quit the Applet Runner by selecting Apple Applet Runner from the menu of active applications in the upper right corner of the screen, then choosing Quit from the File menu,
  3. double-click on the RugWorld.mcp icon to open the second project

The buggles from Problem Set 1, becky, bobby, bertie, billy and benny, had the foresight to copyright their Buggle Olympic Symbol. As a result, they made a killing on the use of the logo for Buggle 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:

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:

pattern 1

pattern 2

pattern 3

pattern 4
The rug itself is created by placing these patterns side by side to tile the entire rug. The rug, divided into 3x3 grids (outlined in black lines), is shown below:

The rug pattern includes a lot of repetitive patterns. This means that there are many opportunities for using methods to generate the pattern efficiently. Your task is to write the code which will create the rug pattern shown above in the most efficient manner you can think of. The code for this problem is contained in the RugWorld folder. The file RugWorld.java contains the initial set-up for creating the rug shown above. becky, bobby, bertie, benny and billy have hired a RugBuggle (another new class of objects which extends the Buggle class) named weaver to produce the rugs. You should add your code to this file, but you should not remove any existing code.

You must observe the following constraints:

Helpful Hints: