[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:
- Java: First Contact, Chapter 7, Chapter 12.1-12.2
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_programs folder you downloaded.
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_programs 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_programs folder. Also, turn in a
hardcopy
of your Rug_BuggleWorld.java
file.
Put the ps3_programs 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
- Be sure to doublecheck that the
your folder and files were actually uploaded.
- Keep a personal back-up of
every file that you upload.
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_programs 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:
- Do not change any of the code already in the file; merely add your own in the
body of the writeC() method.
- Do NOT use the setPosition() method (fred's initial position will be
(1,1) by default, and the initial heading will be EAST). You may use any of the other
Buggle methods to accomplish the task.
- You must leave fred in the position shown above (two squares to the right of
the letter, pointing EAST). Again, do NOT use setPosition() to do this.
- Don't forget to
set the color of the "C" using the letter_color parameter.
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_programs 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 parameter, 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, 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 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_programs folder contains a file named "Rug_BuggleWorld.java". This file
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. 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:
- You should use a single RugBuggle for the entire rug (weaver, who has already been
created in the file).
- You may not, and do not need to, use the setPosition() method. You can use any of
the other Buggle methods.
- You should draw the colors and bagels exactly as shown in the rug.
Helpful Hints:
- You do not need to modify any of the code in the run() method.
- The code for two of the methods "outer_ring(Color c)" and "outer_edge(Color c)" have
been provided for
you. You do not need to change these two methods, but you should use them as an example
for writing other methods.
- When writing the code to draw an individual pattern (e.g. the method for
pattern1(Color c)), think of the buggle as starting
in the lower left corner of the 3 x 3 grid and finishing in position to start the next
pattern element (i.e. in the lower left corner of the next 3 x 3 grid).
- The "turn_corner()" method should change the buggle's position and heading so it is
ready to start dropping bagels along the next edge. This is similar to what you did in
the laboratory assignment.
- The "move_in()" method should move the buggle from the end position from an outer ring
to the starting position in the next inner ring (at the lower lefthand corner of that
ring).
- Avoid using the setDirection() method. It will cause problems when the buggles turn
the corner.
Have fun!