Graphic by Keith Ohlfs |
|
Download the ps1_programs folder from the download directory on nike. Make your modifications to the Writing.java, Rings.java, and Writing2.java files to solve the 3 problems defined in tasks 1 - 3 below. The problems are intended to give you practice writing simple Java code and to introduce you to using methods. All three problems use the BuggleWorld microworld you have been studying in lecture. Do not attempt to do task 3 until you have learned about methods in lecture!
Save the modified Writing.java, Rings.java, and Writing2.java files in the ps1_programs folder to be turned into your drop folder. Turn in a hardcopy of the modified Writing.java, Rings.java, and Writing2.java files.
Put the ps1_programs folder containing the completed source code into your ps1 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 Stanzi's office (E106, across from E101).
IMPORTANT NOTES:
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 the name "ELLIE" in multiple colors:
.
Your assignment:
In the ps1_programs folder there is a file, Writing.java, which contains a Java program to create a single buggle ellie. Add code to the run method to write the name "ELLIE" as shown above.
You must conform to the following rules:
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--becky, bobby, bertie, billy and benny--have agreed to help out in drawing the rings. becky wants to draw the red ring, bobby the yellow ring, bertie the blue ring, billy the cyan ring and benny the magenta 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, bertie, billy and benny are all in the appropriate starting position and are the appropriate color. Fill in the java code to move each buggle around a 7 x 7 square, so that the rings overlap each other as shown.
You must conform to the following rules:
It is possible to use methods to expand the capabilities of the buggle name writing program from task 1. For example, using a larger grid, but fewer actual lines of code, a buggle can write the name "ELLIE" multiple times, around the perimeter of the grid, as shown below:
Your assignment:
Using methods, create the above grid. The file Writing2.java contains Java code which creates a larger grid and defines a LetterBuggle, a new class of objects which extends the Buggle class. A new LetterBuggle named ellie has also been created for you, along with two LetterBuggle methods; writeName, and writeE, as shown below:
// write the name "ELLIE" around the perimeter of the grid public void run () { LetterBuggle ellie = new LetterBuggle(); ellie.writeName(); // add your code here // statements which will write the name around the perimeter of the grid } class LetterBuggle extends Buggle { // write the name "ELLIE", in the appropriately colored letters, by setting the color, // and then by invoking methods for writing the individual letters public void writeName () { this.setColor(Color.red); this.writeE(); // write the first "E", in red // add your code here // statements which will write the "L L I" in the correct colors this.setColor(Color.green); this.writeE(); // write the last "E", in green } //write the letter "E" public void writeE() { this.brushDown(); this.forward(2); // add your code here // the rest of the statements for writing an "E" } // add your code here // methods for writing the other letters in the name }
Perform the following steps to solve the problem:
You must conform to the following rules: