![]() |
Problem Set 1
|
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.
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:
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.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.
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:
setup
that sets the dimensions of the grid
to 21 columns and 7 rows.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.
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:
setPosition()
or
setHeading()
methods.brushUp()
and
brushDown()
where appropriate.setColor()
to change colors).SOUTH
).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.
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:
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).
forward(n)
,
left()
, and right()
methods.