The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 405 Weeks Ago, 5 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
*10.13 (Geometry: the MyRectangle2D class) Define the MyRectangle2D class that contains:
â– Â Â Â Â Two double data fields named x and y that specify the center of the rec- tangle with getter and setter methods. (Assume that the rectangle sides are parallel to x- or y- axes.)
â– Â Â Â Â The data fields width and height with getter and setter methods.
â– Â Â Â Â A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and
1 for both width and height.
â– Â Â Â Â A constructor that creates a rectangle with the specified x, y, width, and
height.
A method getArea() that returns the area of the rectangle.
â– Â Â Â Â A method getPerimeter() that returns the perimeter of the rectangle.
â– Â Â Â Â A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a).
â– Â Â Â Â A method contains(MyRectangle2D r) that returns true if the speci- fied rectangle is inside this rectangle (see Figure 10.24b).
â– Â Â Â Â A method overlaps(MyRectangle2D r) that returns true if the speci- fied rectangle overlaps with this rectangle (see Figure 10.24c).
Â
Â
Â
Â
         Â
         Â
          ![]()
(a)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (b)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (c)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (d)
Â
FIGUREÂ 10.24Â Â Â Â A point is inside the rectangle. (b) A rectangle is inside another rectangle.
(c)Â Â Â A rectangle overlaps another rectangle. (d) Points are enclosed inside a rectangle.
Â
Draw the UML diagram for the class and then implement the class. Write a test program that creates a MyRectangle2D object r1 (new MyRectangle2D(2, 2, 5.5, 4.9)), displays its area and perimeter, and displays the result of r1.contains(3, 3), r1.contains(new MyRectangle2D(4, 5, 10.5,
3.2)), and r1.overlaps(new MyRectangle2D(3, 5, 2.3, 5.4)).
Â
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll