CSE 142 Summer 2001

Homework #1

Due: At the beginning of class, Monday, June 25, 2001

 

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.

Instructions

  1. Find the course software on your computer or one of the lab computers.  (Opening the "MyComputer" icon might be the easiest way to start.)  You should find a folder named CSE142Support [This may be subject to change in the labs - updates will be posted on the web site and mailed to everyone via the cse142-announce mailing list].  Open it.

  2. In this folder, open the folder called "tools".

  3. Now, double click on the icon called "jeva.bat." This should start the Java interpreter. (You should see a window open.)

  4. Experiment with the interpeter. You don't need to turn this in, 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.
    4. 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());

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

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

  6. Start the interpeter again. (Quitting and restarting the interpreter gives you a fresh environment to play in.) We'll ask you to try some things and answer some questions. You can answer them on this sheet.

     

  7. 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?
    
    
    
    
  8. Learn how to create Shapes by specifing all of their qualities. Try the following:
    GWindow g = new GWindow();
    Oval oval = new Oval(100, 150, 30, 60, Color.red, false);
    g.add(oval);
    Rectangle rect = new Rectangle(200, 250, 40, 40, Color.blue, true);
    g.add(square);
    Triangle tri = new Triangle(300, 30, 270, 70, 330, 70, Color.yellow, true);
    g.add(tri);
    
    List at least 3 qualities for that "belong" to each kind of shape: Rectangle, Triangle, Oval.
    
    
    
    
    
  9. Now try the following:
    GWindow.picture();
    
    You should see a picture (something like modern art!). Your job is to show us a sequence of java statements that will draw a similar picture. We don't care too much about the exact positions of the objects, but there should be 5 objects (an oval, a triangle, two filled rectangles, and one unfilled rectangle) that overlap in a manner similar to the provided picture. (The easiest 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 full interface for creating shapes (like the examples above).

    (For the curious, more details about shapes can be found at http://www.cs.washington.edu/education/courses/142/01su/help/javadocs/. Click on the name of the kind of object you want (such as Triangle) to create and the browser should open a page describing the interface for that kind of object.)

    Turn in your the java code you write (you can just copy it by hand, if you wish). You ought to be able to do this in no more than 15 statements (and probably as few as a half dozen). You'll want to start by creating your own graphics window (like the examples above)...