CSE 142 Spring 2002

Homework #1

Art Moderne

Due: At the beginning of lecture, Monday, April 8

 

Steps 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Purpose

The purpose of this assignment is to help you get familiar with the programming lab, your first tool (the interpreter), and to get comfortable using and creating some basic objects.

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.

Instructions

  1. Find the course software on your computer or one of the lab computers.  In the UW lab computers, there will probably be shortcuts that you can find from the START button.  They may have names like jeva-142.bat. Find the shortcut and execute it.  You should see a DOS window like one shown in lecture.

    If you are on a different computer, or working at home, there might not be a short cut.  Try this following instead:

    1. Opening the "MyComputer" icon might be the easiest way to start.  You should find a folder named CSE on the C: drive.  Open it.  In this folder, open the folder called "tools".  
    2. Now, double click on the icon called "jeva-142.bat." This should start the Java interpreter.

  2. Experiment with the Jeva interpreter. You don't need to turn in this step, but doing it will help you get comfortable using it.
    1. Try naming some simple objects (such as integers), like this:
      int myAge = 31;
      double temperature = 67.2;
    2. What's the result of dividing myAge by three? What about temperature?
    3. Try typing in some of the examples that use ArrayList or Strings from the course notes.  Be sure to try some messages on the objects you create, such as length (on Strings).
    4. Try creating a GWindow object and some shape objects, and send each shape a message to add itself to the window.
    5. Finally, learn to use the object inspector, by trying the following:
      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.)

  3. Quit the interpreter. The easiest way to do this is just to click the big X button on the upper right of the window.

    At some point in your experiments, find the jeva-trace.txt file that jeva generates.  This file should be in the same directory as the .bat file you used to start jeva.  It contains a trace of everything that happened in your latest jeva session.  In a future assignment we might ask you to turn this in, or you might find it useful if you need to show someone the outcome of a jeva session.

  4. Start the interpeter again. (Quitting and restarting the interpreter gives you a fresh environment to play in.)

    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).

  5. Start jeva and try the following:
    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?

     



  6. Practice creating Shapes by specifying all of their properties (as arguments when you create them). Try the following:
    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):

     



  7. End Jeva. Now, go to the web and click on the link to download the file Picture.class.  (You may need to right-click on the link and select "save target as..." if your browser tries to open the file.)  Save the file to the disk and place it in the same directory that contains the jeva-142.bat file you use to start Jeva.  (This will be c:\cse\tools, if you set up the CSE142 software following our directions.)

    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.

  8. You're now done with the technical part of the homework.  On paper, answer these questions, briefly:

    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?

  9. Turn in your assignment in lecture on Monday, April 8.  Be sure that your name and quiz section attended are written on your paper, and, if you have more than one sheet of paper, be sure to staple them together.

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!

Steps 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Back to top