Graphic by Keith Ohlfs

CS111, Wellesley College, Spring 1998

Problem Set 3

Due: Friday, February 20 by 4:00 p.m.

[CS111 Home Page] [Syllabus] [Students] [Lecture Notes] [Assignments] [Programs] [Documentation] [Software Installation] [FAQ] [CS Dept.] [CWIS]

Note: The assigned readings which are relevant to this problem set are:

About this Problem Set

There are 3 pieces to this problem set: the prelaboratory assignment, the laboratory assignment and the homework assignment. You are required to do all three parts. We recommend that you do the prelaboratory assignment before your lab section, the laboratory assignment during your lab section and the homework assignment after completing the prelab and lab assignments.

How to turn in this Problem Set

Prelab Assignment: Save your modified CS111_BuggleWorld.java file in the same ps3_Buggles folder you downloaded (you are NOT required to rename the java and html files for this assignment, as you did in assignment 2). You will be further modifying the same file for your laboratory a ssignment, so, this week, you will not need to turn in any items separately for the prelab.

Laboratory Assignment: Save your modified CS111_BuggleWorld.java (which includes the prelab and laboratory solution) in the ps3_Buggles folder. Also, turn in a hardcopy of your CS111_BuggleWorld.java file.

Homework Assignment: Save your modified Rug_BuggleWorld.java file in the same ps3_Buggles folder. Also, turn in a hardcopy of your Rug_BuggleWorld.java file.

Put the ps3_Buggles folder containing the completed assignments into your ps3 drop folder on the cs111 server.

Turn in only one package of hardcopy materials. Staple your files together with the cover page, and submit your hardcopy package by placing it in the box outside of Jennifer's office (E104, directly across from E101).

Reminders

Prelaboratory Assignment

Writing a Buggle Method

In lab last week, part of your assignment was to write a Java program that used a Buggle to draw a letter "C". For the prelab this week, you will perform a very similar task, using a method with a parameter, which you learned about in lecture this past week. Your code should make the applet appear as:

To begin, download the folder ps3_Buggles from the download Directory for CS111. This folder contains three java source files (BuggleWorld.java,CS111_BuggleWorld.java, and Rug_BuggleWorld.java), two html files (CS111_BuggleWorld.html and Rug_BuggleWorld.html), various class files, and the project file, ps3_Buggles.proj.

Open the ps3_Buggles.proj project file by double clicking on it, to start the Symantec Cafe Application. The project window should display the names of the three java source files and the two html files.

Open the CS111_BuggleWorld.java file by double-clicking on it from the project window. Your job is to add the code for the writeC(Color letter_color) method, which is used by a letterBuggle (a new class of objects which extends the Buggle class) named fred to write a letter "C" in the CS111_BuggleWorld grid, in a color specified by the parameter letter_color .

The following are the rules you must follow:

When you have made your modifications, save the file, and Bring Up to Date. Start the Applet Viewer, and open the CS111_BuggleWorld.html file. When you are done, save the CS111_BuggleWorld.jave file in the same ps3_Buggles folder, and bring it to Lab next week. We will make further changes to the file for the laboratory assignment.

Laboratory Assignment

More Coding with Methods

Methods for "S" and "1"

Now that our letterBuggle fred has had some practice writing a "C", we are going to create some additional letterBuggle methods, so he has more to do. Add two methods to the CS111_BuggleWorld.java file, one to write an "S", and one to write a "1", as shown below:

Follow the same rules as for the letterC() method from prelab to write letterS() and letter1() methods. Each should take a color paramter, as well. To test your code, change the method invocation in the run()method from letterC(Color.red) to letterS(Color.blue) .

Then, do the same for letter1(Color.black) .

A Method for "CS111"

Write "CS111" with your three methods; it should appear as follow:

Notice how easy it was to do the "111" part! Fred is so excited by finally being able to spell the course name that he would like a method to do so any time he likes. So, create another method in the letterBuggle class which can write "CS111", and call the new method CS111() . Will it have any parameters?

Fred Goes Crazy

fred loves to write "CS111" with the method so much that he wants you to find a way for him to re-use the method within the CS111_BuggleWorld. As your last task today, make fred happy by using multiple invocations of the CS111() method to create the following:

"

You will need to come up with a way to turn and change your heading at each corner of the grid. Let's work on this together.

Final Results

Your final CS111_BuggleWorld.java file should include the methods for writing "C", "S", "1", "CS111", and code to produce the last grid shown.

Homework Assignment

The Buggle Bagel Ruggle Company

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:

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:

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):

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 laboratory assignment.

The ps3_Buggles folder contains a file named "Rug_BuggleWorld.java". This file contains the initial set-up for creating the rug shown above. becky, bobby, and bertie have hired a RugBuggle (another new class of objects which extends the Buggle class) named weaver to produce the rugs. The file has stubs for the methods which you need to write to accomplish the task. You should add your code to this file, but you should not remove any the existing code. You must observe the following constraints:

  1. You should use a single RugBuggle for the entire rug (weaver, who has already been created in the file).
  2. You may not, and do not need to, use the setPosition() method. You can use any of the other Buggle methods.
  3. You should draw the colors and bagels exactly as shown in the rug.
Have fun!