About this Problem Set
This problem set is will help extend your knowledge of Java methods and parameters. There's also an ungraded challenge problem for anyone interested in testing the limits of their programming savvy. There is a contest associated with the challenge problem (please see below) with PRIZES (hint: think Bagels!).
To get the code for this assignment, connect to the cs111
download directory via Fetch and download the folder
ps03_programs.
How to turn in this Problem Set
Save the modified Writing3.java and
RugWorld.java files in the ps03_programs
folder. Submit the entire ps03_programs folder to your
drop folder on the cs111 server.
Turn in a hardcopy of your modified Writing3.java and
RugWorld.java files. If you chose to work on the
ungraded challenge problem, you should also turn in the
FontBuggle.java and HuggleWorld.java
files.
When submitting your hardcopies, turn in only one package of materials. Please staple your files together with a cover page, and submit your hardcopy 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:
- Pay careful attention to upper and lower case letters in the filenames.
- Once you have used
Fetchto upload a file to the cs111 server, you should be sure to doublecheck that the file was actually uploaded. You can do this inFetchby 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 of0K. If the file isn't listed or if the size for the document is0K, 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. - 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. Please make sure to keep a copy of your work, either on your own computer (or some other storage medium), or in your private directory (or, to play it safe, both).
Task 0: Meet the Instructors
In the previous two weeks, you met one of the instructors (Stella or Mark) during her/his office hours. (Some of you may have seen us both already — great job!) This week, you must meet the other one of us! Go to the other instructor's office hours and secure a sticker (you cannot see the same person you saw last time!). If you cannot make office hours, you must schedule an appointment. Place the sticker on the problem set cover page. Now you have met both of us!
You will receive a 0 on an assignment for each missing sticker, and we will NOT give you a sticker in class or lab. This is the last week to get a sticker.
Task 1: Buggle Word Writing using Methods (the last chapter)
This task uses methods to expand the capabilities of the buggle word writing program from problem sets 1 and 2. In this problem, a buggle can write a more colorful "JAVA" around the perimeter of the grid, as shown below:
Your assignment:
Using methods, create the above grid.
Create a new Java file
Writing3.java, which will be similar to the
Writing2.java file from the previous problem set. You
can, and as a matter of fact you are encouraged to, re-use code from
your previous assignment. In particular, the methods you defined in
Problem Set 2 to write the individual letters (J, A, and V) do not need to
change at all for this task.
You only need to change the writeName() method, to make
it more flexible, so it now produces multi-colored JAVA words, instead
of uni-colored ones! Of course, the way the
writeName() method is called/invoked, in the run() method,
should change as well, to reflect the changes in its definition.
All the rules from Task 2, in Problem Set 2 hold here as well.
Task 2: The Buggle Bagel Ruggle Company
Important note: Before you begin working the third task, make sure to save and close all Java files from the previous task.
The buggles from Problem Set 1 (blithe, cy, maggie, rex and yelena) 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/color patterns:
pattern1(Color.black, Color.yellow) |
pattern2(Color.black, Color.yellow) |
pattern3(Color.black, Color.yellow) |
pattern4(Color.black, Color.yellow) |
Each of these 4 patterns is parameterized by two colors that allow different colors to be used in different situations.
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:
Your task is to write code that draws the rug pattern shown above. This rug pattern is composed of many repeated subpatterns. This means that there are many opportunities for using methods to simplify the drawing of the rug pattern. Your goal is to describe as many subpatterns as you can using methods to avoid writing statements for the same subpattern twice.
The code for this problem is contained in the RugWorld
folder. You will be editing the file RugWorld.java.
This file contains the complete definition of a
BuggleWorld subclass named RugWorld
(which you should not change) and the skeleton of a
Buggle subclass named RugBuggle
that you must flesh out. The run() method of the
RugWorld class creates a single RugBuggle
named weaver that draws the entire rug via the
makeRug() method in the RugBuggle class:
public void run() { RugBuggle weaver = new RugBuggle(); weaver.brushUp(); weaver.makeRug(); }
Note that weaver's brush is up when it starts
drawing the rug.
You must observe the following guidelines to complete this task:
- You should not modify the
RugWorldclass. - Your task is to edit the
RugBuggleclass by (1) fleshing out the provided skeleton for themakeRug()method; (2) defining all the methods described below; and (3) defining any additional methods you think are helpful. - You may not, and do not need to, use the
setPosition()orsetHeading()methods. You can use any of the otherBugglemethods. - Your
makeRug()method must draw the colors and bagels exactly as shown in the above rug picture. - When the
makeRug()method is invoked on a buggle, its final position and heading must be the same as its initial position and heading. - Each 3x3 grid in the rug must be generated by using one of the four 3x3 patterns shown above.
- In each 3x3 pattern, the buggle must start in the bottom left corner facing rightward. The buggle must finish in a position to start the next 3x3 pattern to the right. For example:
-
You must name the methods that generate each of the four patterns above
pattern1(),pattern2(),pattern3(), andpattern4(), respectively. Each pattern should take twoColorparameters. For example, the skeleton for thepattern1()method should look like this: - You must also define the following methods:
-
outerRing(): this method draws the outer ring. It should have twoColorparameters. The first color parameter represents the outer color of the border (blue in the rug you are drawing) and the second color parameter represents the inner color of the border (red in the rug you are drawing). A snapshot of the rug after invokingouterRing(Color.blue, Color.red)is shown below: innerPattern(): this method draws the inner pattern shown below that is repeated twice in the rug:innerRing(): this method draws the border of the inner pattern. This method should also have two Color parameters.
For example, innerRow(): this method draws the pattern in the center of the inner pattern. This method should have two Color parameters. For example,innerRow(Color.black, Color.yellow)should draw the following pattern:-
centerRow(): this method draws the pattern in the center of the rug. This method should also have twoColorparameters.
|
|
public void pattern1 (Color c1, Color c2)
{
// Write statements to draw pattern1 here.
}
This skeleton happens to use the parameter names c1
and c2, but you can use whatever parameter names you like.
This method takes two Color parameters
that determine the colors used in the pattern.
For example, the above picture was created by the invocation
innerPattern(Color.black, Color.yellow).
Note that the actual rug uses the
colors cyan and pink in one instantiation of the pattern and green and
orange in the other instantiation of the pattern.
innerRing(Color.black, Color.yellow) should draw
the following pattern:

Like
makeRug(), the five methods above must meet
the invariant that the buggle must start and finish in the same cell,
facing the same direction. You should assume that the buggle starts in the
bottom left corner of each pattern (as drawn above) facing rightward
and should finish that way.
-
The
BugglemethodsetCellColor(Color c)can be used to paint the cell under the buggle a certain color without having to move the buggle. For example, weaver's brush is initially up before making the rug.-
You can temporarily modify the
run()method to test out small parts of your code. Comment out the invocation ofmakeRug()and replace it by the code you want to test. Remember that you can comment out a line of code by adding//(two slashes) before that line of code. -
The row patterns are created by alternating patterns 3 and 4 like so (pattern3–pattern4–pattern3):
- You should feel free to add as many more methods as you see fit. There are many more opportunities for creating methods in this problem. In particular, the four 3x3 patterns share many common subpatterns that can be factored out with methods.
will paint the cell under
sara gray. sara's brush state is not changed
by the invocation of the setCellColor() method.
Non-Graded, Non-Credit Challenge Problem: HuggleWorld
Up for a challenge? Here's a golden opportunity to put your buggle skills to the test. Design greetings cards and win a bag of baggles. Click here for more details.