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 larger rectangle.


From Big Java 4th Edition


Need help computing the correct answer

Verified Answer :

' if the rectangles were drawn, they would form one larger rectangle.'
That part of the question I don't get.
To print the location of the Rectangle write a toString method in the
Rectangle class.
When using the System.out.println method the toString method of that
object will be called.

If you have to translate the rectangle only when the
System.out.println() methode is used you should translate the rectangle
object in the toString methode.
So the translate method keeps the translated cordinates, but only
translates the rectangle when the toString is called.

So the to string method would be something like that:
String toString(){

return "X-cord.: "+ (this.X1+this.translatedX) +"-"+
(this.X2+this.translatedX) +"
Y-cord.:"+(this.Y1+this.translatedY)+"-"+(this.Y2++this.translatedY);
}