Sample Test for chapters 1-3 of Java: An Eventful Approach

 

Write statements to instantiate each of the following objects with the given properties. You may assume that objectdraw objects are created on a DrawingCanvas called canvas.

 

1.      A variable of type FramedOval located at point (20, 100) with width 50 and height 100.

 

 

 

2.      A variable type Location with x=5 and y=10.

 

 

 

3.      A variable of type Line which represents a horizontal line that is 50 units long.

 

 

 

4.      Draw a picture of roughly where and what the FramedOval from question 1 would look like if it were displayed in the box below.  Consider the box below to be the typical 300 x 200 applet window.

 

 

 

 

 

 

 

 

 

 

 

 

 

5.      At what coordinate would the FramedOval from question 1 be located after calling the move method with parameters (100, 0).

 

 

 

 

6.      Give an example of a compound boolean expression. 

 

 

 

 

7.      Write the class definition for class Frog.  Frogs have a FilledOval body, two FilledArc eyes, a Color and a Location.  Frogs also have the following 5 methods.

 

Do not implement the methods.

 

  1. A constructor with a Location parameter and a DrawingCanvas parameter.
  2. A move method which takes two parameters and functions like the FramedRect move method.
  3. A setColor method that takes a Color parameter and changes the frog’s color.
  4. A getX() method that returns the x coordinate where the Frog is constructed.
  5. A getY() method that returns the y coordinate where the Frog is constructed.

8.      Write a code segment that would belong in a class that uses class Frog.  This code segment should properly instantiate a private Frog variable called jumper to be at point (160, 50) on the WindowController canvas and assign the frog a random color.  Any needed variables other than jumper including randomizers should be declared locally.

 

 

 

 

9.      Consider implementing a new class that extends WindowController.  This class has a Frog variable called jumper declared privately.  You are asked to implement the appropriate mouse event in order to accomplish the following task.

 

If the mouse click is below y=160 and if the mouse click is to the left of the Frog variable then move the Frog 10 units to the left.  If the mouse click is below y=160 and to the right of the Frog variable then move the Frog 10 units to the right. Hint: the move method will accept negative values as parameters.