anonymous
  • 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
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • 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
anonymous
  • 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); }

Looking for something else?

Not the answer you are looking for? Search for more explanations.