Exercise 1:
Write a program called FourRectanglePrinter that constructs a
Rectangle object,
prints its location by calling System.out.println(box), and then
translates and prints
it three more times, so that is the rectangles were drawn, they
would form one
large rectangle, as shown at right.
Your program will not produce a drawing. It will simply print the
locations of the four rectangles.
import java.awt.Rectangle;
public class FourRectanglePrinter {
public static void main(String[] args) {
Rectangle box1 = new Rectangle(100, 100, 50, 100);
System.out.println(box1);
Rectangle box2 = new Rectangle(100, 200, 50, 100);
System.out.println(box2);
Rectangle box3 = new Rectangle(150, 100, 50, 100);
System.out.println(box3);
Rectangle box4 = new Rectangle(150, 200, 50, 100);
System.out.println(box4);
}
}
Output:
Get Answers For Free
Most questions answered within 1 hours.