# Drawrectboundx boundy boundwidth boundheight then the

• Notes
• UltraLightningCobra8457
• 28

This preview shows page 15 - 19 out of 28 pages.

g.drawRect(bound.x, bound.y, bound.width, bound.height); } then the window would appear as shown below: Define the boundingRect() method in the space provided below. Remember, this method should return a new Rectangle object which represents the smallest possible rectangle that completely contains all Rectangle objects in the array passed to the method as a parameter. Notice that the rectangle bound has been created by the boundingRect() method so that it just encloses all the other rectangles.

Subscribe to view the full document.

Question/Answer Sheet - Page 16 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ........................................................... CONTINUED You must define the boundingRect() method below so that it works for any array of Rectangle objects. You can assume that the array contains at least one Rectangle object. private Rectangle boundingRect(Rectangle[] rects) { int minX = rects[0].x; int minY = rects[0].y; int maxX = rects[0].x + rects[0].width; int maxY = rects[0].y + rects[0].height; for (int i = 1; i < rects.length; i++) { if (minX > rects[i].x) minX = rects[i].x; if (minY > rects[i].y) minY = rects[i].y; if (maxX < rects[i].x + rects[i].width) maxX = rects[i].x + rects[i].width; if (maxY < rects[i].y + rects[i].height) maxY = rects[i].y + rects[i].height; } Rectangle result = new Rectangle(minX, minY, maxX - minX, maxY - minY); return result; (10 marks) }

Subscribe to view the full document.

Question/Answer Sheet - Page 18 - CompSci 101 SS C SURNAME: ...................................................... FORENAMES: ...........................................................
You've reached the end of this preview.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern