CS111, Wellesley College, Fall 2007

Problem Set 1

Due Tuesday 11 September at the start of class

Reading

About this Problem Set

This problem set will get you acquainted with your instructors, with the mechanics of CS111 programming, and with basic Java coding.

On each of the first three assignments, you must secure a sticker from a different instructor (Brian, Lyn, Stella) by visiting office hours or otherwise arranging a meeting (see Task 0). You'll put this sticker on your cover sheet (see below). After three assignments, each of us will have seen all of you!

Download the ps01_programs folder from the cs111 server by using the cs111d account and the password provided in lab. Rename this folder Wendy_ps01, except, of course, you should replace Wendy with some word that uniquely identifies you. Create and code a Writing.java file and make your modifications to the given Rings.java file to solve the 2 problems defined in the two tasks below. The problems are intended to give you practice writing simple Java code. Both problems use the BuggleWorld microworld you have been studying in lecture.

How to turn in this Problem Set

Create a new file called Writing.java and save your modified Rings.java files. Print out a hardcopy of your final versions of the Rings.java and Writing.java files.

Upload the ps1 folder containing your modified files into the ps1 drop folder on the cs server.

Turn in only one package of materials. Staple your files together with a cover page, and submit your hardcopy package at the start of class on the due date. Don't forget to put one of the instructors' stickers on the cover page!

IMPORTANT NOTES:

  1. Pay careful attention to upper and lower case letters in the filenames.
  2. Once you have used Fetch to upload a file to the cs server, you should be sure to doublecheck that the file was actually uploaded. You can do this in Fetch by verifying that the file is now listed in your directory. Not only should you check that the file is listed, but you should check that it does not have a size of 0K. If the file isn't listed or if the size for the document is 0K, this means that there was an error in transferring it via Fetch and you must re-upload the document. When transferring a folder, you should check that its contents have been uploaded correctly. That is, you should be sure to check that every single file that you wish to submit has been uploaded correctly. Often times, although not always, you will see a message "Connection Failed" when there is an error in transferring your files.
  3. Be sure to keep a backup copy either on your own computer, in FirstClass, or on a USB drive, CD/DVD, or some other medium. This will protect you in the event of data lossage on the department server.

Task 0: Meet the Instructors

We want to ensure that each of us meets all of you, and that everyone is comfortable coming to see us. So, for the first three problem sets, you will be required to drop in on someone's office hours (or schedule an appointment if that isn't possible). Each week you must meet a different one of us, and it doesn't matter what order you meet us in.

Go to the office hours of one of the instructors (Brian, Lyn, and Stella). If you cannot make office hours, you must schedule an appointment. Go to the instructor's office and secure a sticker from the instructor you meet. Place that sticker on the problem set cover page.

You cannot get credit for this assignment without a sticker, and we will not give you a sticker in class or lab.

Task 1: Buggle Writing

In lecture and lab, we have learned that in BuggleWorld, buggles can be used to make patterns or write letters within a grid. Below, a single buggle has written "PS1!" in multiple colors:

.

Your assignment:

In your ps1 folder, create a new file called Writing.java that defines a subclass of BuggleWorld named Writing. Like the Cs.java file from Lab 1, your Writing.java file should begin with comment indicating your name and the fact that this is your solution to Task 1 of CS111 PS1. This comment should be followed by the line:

import java.awt.*;

This line allows you to refer to Java's Color class in the rest of the file. (AWT stands for Abstract Window Toolkit, and names the Java library defining the Color class and many other classes related to graphics.)

Like the Cs class, your Writing class should have three methods:

  1. An instance method named setup that sets the dimensions of the grid to 21 columns and 7 rows.
  2. An instance method named run that creates a single buggle to write "PS1!" (with bagels after the P and S) as shown above. By the way, the color of the S is magenta.
  3. A class (i.e., static) method named main that uses runAsApplication to allow the Writing applet to be run as a Java application. (Every subclass of BuggleWorld we create in this course will have such a main method. You don't have to understand how it works, but you must include it!)

You must conform to the following rules in your run() method:

  1. You must use a single buggle to perform all drawing.
  2. You may not invoke the setPosition() or setHeading() methods.
  3. You should use the methods brushUp() and brushDown() where appropriate.
  4. The letters "P" and "S" should fit in a 6 column x 7 row grid, and should be separated from the next letter by one cell containing a bagel and one blank cell.
  5. The numeral "1" and the exclamation point should each occupy a 1 column x 7 row grid as shown.
  6. Your buggle must draw the characters in the appropriate colors (use setColor() to change colors).
  7. Your buggle must end up in the position shown above, facing the correct direction (SOUTH).
  8. Please comment your code. You needn't comment every line, but should comment groups of lines that perform an important subtask (e.g., drawing the letter S).

If your buggle isn't working properly, you are encouraged to use the BuggleWorld Step button to step through your program to see where it goes wrong.

Task 2: The Buggle Olympic Symbol

In BuggleWorld, the buggles regularly hold competitions in which they run the hurdles or traverse obstacle courses. Because they enjoy these competitions so much, they have decided to hold the first Buggle Olympics. To prepare for the big event, they have decided they need an appropriate symbol. They like the idea of interlocking rings, but due to the constraints of BuggleWorld, their rings have to be squares instead of circles. They have designed the following logo for their Olympics:

Five buggles — blithe, cy, maggie, rex and yelena — have agreed to help out in drawing the rings. blithe wants to draw the blue ring, cy the cyan ring, maggie the magenta ring, rex the red ring, and yelena the yellow ring. Each would prefer to draw only in one color and not change colors in the middle of their ring. Furthermore, they would prefer not to have to put their brushes up and down while drawing their rings. They have asked you to help them choreograph their movements so that the rings get drawn the correct way, with each ring overlapping the others as shown above.

Your assignment:

The file Rings.java contains a skeleton run() method with some code initializing the starting positions, headings, and colors of blithe, cy, maggie, rex and yelena. Flesh out the rest of the run() method to move each buggle around a 15 x 15 square, so that the rings overlap each other as shown.

You must conform to the following rules in your run() method:

  1. You may not invoke the setColor(), setPosition(), brushUp(), or brushDown() methods beyond the initialization code given to you in the run() method. (I.e., setColor() and setPosition() are used only once for each buggle).
  2. The buggles should use only the forward(n), left(), and right() methods.
  3. The final position and heading of each buggle should be the same as its initial position and heading. These are the buggle positions and headings shown in the above picture.
  4. Each buggle should traverse its square ring only once. It should not revisit any square it has already visited, except for the starting square, which it ends on.
  5. Pay careful attention to the color of the squares where the rings intersect. You must get the buggle of the appropriate color to cross these intersections after the other buggle. This means that a buggle may have to stop in the middle of its drawing and wait for another buggle to complete a portion of its ring before it can continue.
  6. Please comment your code --- not only to help the grader, but also to help yourself!