127k views
3 votes
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, if 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.

User Ivcubr
by
7.9k points

1 Answer

5 votes

The program called FourRectanglePrinter constructs a Rectangle object, prints its location by calling System.out.println(box), and then translates and prints it three more times, so that, if the rectangles were drawn, they would form one large rectangle. This will print the location of the four rectangles.

Step-by-step explanation:

import java.awt.Rectangle;

public class FourRectanglePrinter

{

public static void main(String[] args)

{

System.out.println(" ");

Rectangle box = new Rectangle(10, 20, 30, 40);

System.out.println(box);

System.out.println(" ");

box.translate(0,30);

System.out.println(box);

box.translate(40,0);

System.out.println(box);

box.translate(40,30);

System.out.println(box);

}

}

The above code is done in java.

User Drewdavid
by
7.2k points