Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

{ Rectangle box = new Rectangle(0,10,20,20); Rectangle box2 = box; box2.translate(5, 0); Rectangle box3 = box; box3.translate(0, -10); Rectangle box4 = box; box4.translate(5,-10); System.out.println(box); System.out.println(box2); System.out.println(box3); System.out.println(box4); } This is what I have so far

OpenStudy (anonymous):

' 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); }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!