CSE 142 Spring 2002Homework #1Art ModerneDue: At the beginning of lecture, Monday, April 8 |
The instructions are given in the form of a tutorial. Many of the steps are here just to give you practice, and won't result in anything that you have to hand in. At the end, there is a final step that asks you to figure out a sequence of Java statements to draw a picture. Your written answers to that problem, along with answers to a couple of questions about this assignment, should be handed in at the beginning of your lecture on Monday, April 8.
If you are on a different computer, or working at home, there might not be a short cut. Try this following instead:
int myAge = 31;
double temperature = 67.2;
Rectangle rect = new Rectangle(); OBrowser.inspect(rect); OBrowser.inspect("hello bob"); OBrowser.inspect(new ArrayList());
Try sending rect
a message (such as moveTo
) and use the inspector to see what happened.
(Hint: If you need to type a statement that is similar to one you've used before, try hitting the up-arrow key. This key takes you through a "history" of your previous inputs. With it, you can go back to a previous input, and using the left-arrow key and delete you can edit it to your taste. This works with the console window in Windows 2000 and, presumably, Windows XP. It might not work in earlier versions of Windows.)
Now we'll ask you to try some things and answer some questions, for your own practice. You can write the answers on this sheet (you won't have to turn this in).
Pen p = new Pen(); p.turn(37); p.move(100);
What is the position of the pen? (Hint, use the inspector!)
Now send the pen home and draw a squiral:
p.home(); p.erase(); p.squiral(100, 123, 5);What is the position and angle of the pen?
GWindow gwin = new GWindow(); Oval oval = new Oval(100, 150, 30, 60, Color.red, false); oval.addTo(gwin); Rectangle rect = new Rectangle(200, 250, 40, 40, Color.blue, true); rect.addTo(gwin); Triangle tri = new Triangle(300, 30, 270, 70, 330, 70, Color.yellow, true); tri.addTo(gwin);
List at least 3 properties that "belong" to each kind of
shape: Rectangle
, Triangle
, Oval
(you do not have to hand this in):
Now restart Jeva and enter the following:
Picture.drawPicture();
You should see a picture (something like modern art!). A copy of the picture is also available if you follow this link on the web.
Your job is to show us a sequence of Java statements that will draw a similar picture. The exact positions and sizes of the shapes are not critical - don't waste your time getting out a magnifying glass and counting the pixels - but there should be 5 objects (a circle, an oval, a triangle, a filled rectangle, and an unfilled rectangle) that overlap in a manner quite similar to the provided picture and have similar if not identical colors and sizes. (One way to do this is to sketch out the positions on a piece of paper before creating the objects.) . Create the objects by using the interface for creating shapes (like the examples above). You'll want to start by creating your own graphics window. You ought to be able to paint the picture in no more than 15 statements (and probably fewer).
Write down your final sequence of statements on a piece of paper. An easy way to do this would be to print out the jeva-trace.txt file produced by jeva when you enter the statements to draw the picture.
More details about shapes can be found by following this link: http://www.cs.washington.edu/education/courses/142/info/java/docs.html, which is also on the course homepage.
a. (required) What worked and didn't work in your solution to the Modern Art problem?
b. (required) How much help did you get in doing the assignment, and from whom?
c. (optional) What would you like to learn next about programming, now that you're at this stage?
You will be graded on the correctness of your answers, as well as on following directions properly. For example, if you e-mail your files instead of turning them in in the manner requested above, you won't get full credit.
Have fun!