CS111, Wellesley College, Spring 1998

Problem Set 2

Text Only Version

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

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

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 html file that contains the applet tags in a text file named <your-user-name>_coalesce.html and put it into your folder in the ps2 drop folder on the cs111 server. Turn in a hard copy of this html file.

Note:Although we expect you to do the prelab before coming to lab, you do not need to hand this in until the assignment due date (February 13).

Laboratory Assignment: Rename the BuggleCS.java file and the BuggleCS.html file as <your-user-name>_BuggleCS.java and <your-user-name>_BuggleCS.html. Remember that you must also change the name of the class and the invocation of the applet in the html file to reflect this name change. Save these files in the Buggles folder you downloaded. Turn in a hardcopy of the <your-user-name>_BuggleCS.java file.

Important Note: Pay careful attention to upper and lower case letters in the filenames.

Homework Assignment: Rename your modified Writing.java and Writing.html files <your-user-name>_Writing.java and <your-user-name>_Writing.html .
Rename your modified Rings.java and Rings.html files <your-user-name>_Rings.java and <your-user-name>_Rings.html. Save these four renamed files in the Buggles folder with your laboratory assignment files.

Turn in a hardcopy of the <your-user-name>_Writing.java and <your-user-name>_Rings.java files.

Put the Buggles folder containing the completed laboratory and homework source code into your ps2 drop folder on the cs111 server.

When submitting your hardcopies, we ask that you turn in only one package of materials. Please staple your files together with a cover page, and submit your hardcopy package by placing it in the box outside of Jennifer's office (E104, directly across from E101).

IMPORTANT NOTE - Once you have used Fetch to upload a file to the cs111 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.

ANOTHER IMPORTANT NOTE - It is your responsibility to keep a personal back-up of every file that you submit electronically until you have received a grade for the assignment.

Prelaboratory Assignment

Invoking applets from the web.

Read the information on how to invoke applets from the web.

From the documentation page, click on the "Instant Java" link to go to the instant Java Applet Repository. Click on "Assorted Applets". From there, click on "CoalesceContinuous". (Alternatively, click here to go there directly ). In the menu bar of Netscape, you can note that the location of the current page is:

"http://www.vivids.com/ij2/assorted/CoalesceContinuous.html".

You will see some applet code on the Instant Java page; Do not use this code! Instead, from the Netscape File Menu, choose "View Document Source" and find the applet tags that this web page actually uses.

Select everything from <applet... to </applet> on the HTML source page and copy it. Save it into a text file on your local Mac (you can use the Symantec Project Manager editor to do this, or a text editor such as SimpleText. Do not use a word processor, such as Word). Insert enough HTML tags to create a minimal web page that you can view with netscape:

<HTML>
<HEAD>
</HEAD>
<BODY>
The Applet goes here
</BODY>
</HTML>

Save this file as a text file, named <your-user-name>_coalesce.html

Changing the applet codebase

You must now change the applet codebase so that it gives the absolute address of the directory at the Instant Java Site where the CoalesceContinuous class file resides. Note that the code you copied gives the following codebase:

codebase = ../AllClasses

This means that the class files resides in a directory named "AllClasses" which resides in the directory that is one above (In the directory hierarchy) the directory that the CoalesceContinuous.html file resides in. Noting the address of the CoalesceContinuous.html file, you can find the appropriate directory as follows:

Change your applet so that it contains the absolute address of the codebase.
View your page with Netscape and make sure it works.

Making the Applet your own

Now, change the text in the applet to be a message of your choice. You will need to change the parameter called "TextCount" (the number of lines of text) and the parameters called "text1", etc. (Note: you may have to quit and restart Netscape to see the changes. Reloading does not seem to help in this situation). Save your file (still named <your-user-name>_coalesce.html) and upload it to the ps2 drop folder.

Laboratory Assignment: Buggle Writing

1. Modifying an Applet

In lecture you were introduced to Buggleworld. In this world you can create "Buggles" that can move in different directions and draw onto their grid world. Today in lab you will learn how to use the Symantec project manager to modify an applet that uses Buggles. We will first download some pre-written applets, BuggleCS, Writing and Rings, from the download subdirectory of cs111 on the cs111 server.

1) First, download the folder, Buggles, from the download directory for cs111. This folder contains four java source files (BuggleWorld.java, BuggleCS.java, Writing.java and Rings.java), three html files (BuggleCS.html, Writing.html and Rings.html), many class files and one project file. Make sure all the icons are displaying the proper images (e.g. a coffee cup on the class files). If they are not, download the fetch preferences again and try again.

2) To run the BuggleCS applet, take the following steps.

Renaming .java and .html files

Together we will change the name of the BuggleCS.java and BuggleCS.html files to:

Note: When you change the .java filename, you must also change the class name in both the .java file and the .html file.

Dealing with Common Errors (In Class)

When programming in Java, you will often make mistakes typing or in designing your program code. These mistakes will lead to two types of errors: Compiler errors, which cause error messages during the compilation of your program, and run-time errors, which allow the program to compile, but cause it to do the wrong thing. These errors are often called "bugs". Knowing how to find and correct bugs in your code (known as debugging) is an extremely important skill for a programmer. We will examine the following common types of errors (one at a time).

Making the buggles write

Together we will change the code, so that becky buggle draws the letter "C", as in Figure 2: Buggle C

2. Modifying Your Own Applet (To be handed in)

Now that you've had a chance to modify and debug some code, it's time to try it on your own. Modify <your-user-name>_BuggleCS.java file so that becky draws the "C" as before, and bobby draws an "S" as in Figure 3: Buggle CS

Homework Assignment: More Coding with Buggles

Task 1: Another way to write "C S"

In BuggleWorld, the Buggles have all become very excited about their newfound ability to write, which you provided them in the laboratory part of this assignment. However, they are sad that it took the efforts of two buggles working together to write two letters. This is not ideal if one of them would like to write a note to another. They have hired you as a consultant, to help individual buggles write more than one letter. Your job, is to make the buggle, becky, write the letters C S as shown above, without the help of the buggle, bobby.

Because becky gets tired if she has to make too many large jumps around BuggleWorld, she has requested that you show her how to write "CS" without invoking the "setPosition" method. She is perfectly happy to lift her brush up (by invoking the method "brushUp") and put her brush down (by invoking the method "brushDown") so that she will only leave a trail when required. She also likes the idea of writing with multiple colors, so she would like to write the C in red and the S in yellow.

Your assignment:

In the Buggles folder there is a file, Writing.java. This applet creates buggle becky and sets her color to red. First, change the name of this file and the associated Writing.html file to <your-user-name>_Writing.java and <your-user-name>_Writing.html . Remember to change the name of the class file within the two files to match the new .java file name.

Modify the Writing.java code so that becky draws the letters "C S". The resulting letters should look as in Figure 4: Buggle Writing.

You must conform to the following rules:

  1. You may not invoke the "setPosition" method.
  2. You should use the methods "brushUp" and "brushDown" where appropriate.
  3. Becky must draw the letters in the appropriate colors (use "setColor" to change colors).
  4. Becky must end up in the position shown above, facing the correct direction (WEST).

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, they can only fit 3 interlocking rings (instead of 5) and their rings have to be squares instead of circles. They have designed a logo for their olympics, shown in Figure 5: Buggle Rings.

Three buggles--becky, bobby and bertie--have agreed to help out in drawing the rings. becky wants to draw the red ring, bobby the yellow ring and bertie the blue 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 the initial set-up for drawing the olympic rings. becky, bobby and bertie are all in the appropriate starting position and are the appropriate color.

First, save the Rings.java and the Rings.html file as <your-user-name>_Rings.java and <your-user-name>_Rings.html . Remember to change the name of the class file within the two files to match the new .java file name.

Now, you must fill in the java code to move each buggle around a 5 x 5 square, so that the rings overlap each other as shown. You must conform to the following rules:

  1. You may not invoke setColor, brushUp, brushDown or setPosition methods beyond what is given you in the initial set-up file (i.e. setColor and setPosition are used only once for each buggle). The buggles use only the forward(n) and left() methods.
  2. Each buggle should traverse their square ring only once. They should not revisit any square they have already visited, except for the starting square, which they end on.
  3. Pay careful attention to the color of the squares where the rings intersect. You must get the buggle of the appropriate color 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.