// File: ClassEx02.java // A simple test class to give students experience creating objects and // calling accessor and mutator methods // USE LINES 14 TO 36 FOR REFERENCE // ============================== import java.awt.Rectangle; public class ClassEx02 { public static void main(String[] args) { // create a Rectangle object Rectangle shoeBox = new Rectangle(5, 10, 20, 30); // "local" variable declarations double xValue; // x location of a Rectangle double yValue; // y location of a Rectangle double width; // width of a Rectangle double height; // height of a Rectangle // call accessor methods to get shoeBox x and y // REVIEW: calling methods that RAV in assignment statements xValue = shoeBox.getX(); yValue = shoeBox.getY(); // print shoeBox x and y System.out.println("The upper-left corner of shoeBox is at (" + xValue + "," + yValue + ")") ; // get and print shoeBox width and height // REVIEW: Calling methods that RAV as the argument to another method // (i.e. println) System.out.println("The shoeBox is " + shoeBox.getWidth() + " x " + shoeBox.getHeight() + "\n"); // ================================================================= // EXERCISE 1: Create a new Rectangle object with a name of your own // choosing, and x, y, width, and height of 54, 40, 20, and 25 // respectively. Then, call the "get" methods to get and print the // "state" (x,y,width,and height) of your Rectangle. // HINT: you can use the local variables declared above, declare new // ones, or neither (call the methods as the argument to println) // ================================================================= // ================================================================= // EXERCISE 2: call the translate() method to move your Rectangle // 20 units up and 75 units to the right. Then, get and pring the new // location of your Rectangle. // ================================================================= // ================================================================= // EXERCISE 3: call the rectangle class move() method to move the // shoeBox to point (37,73). The move methods takes 2 int arguments // which are the new x and y coordinates of a Rectangle. I.e., it // moves a Rectangle to the given coordinates. Then, call the "get" // methods to get and print the new coordinates // ================================================================= } }