A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

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

  • This Question is Open
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    { 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

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.