Question: Implement the class Rectangle.java, containing two pairs of coordinates the lower left and upper right corners of the rectangle (assuming all the edges are parallel/perpendicular

 Implement the class Rectangle.java, containing two pairs of coordinates the lower

left and upper right corners of the rectangle (assuming all the edges

Implement the class Rectangle.java, containing two pairs of coordinates the lower left and upper right corners of the rectangle (assuming all the edges are parallel/perpendicular to the x axis). Write getters and setters for each coordinate. Rectangle - lowerLeftX : double get/set - lowerLeftY : double get/set - upperRightX : double get/set - upperRightY : double get/set + Rectangle() + Rectangle(double, double) + Rectangle(double, double, double, double) + area() : double + perimeter() : double + distanceFromOrigin() : double + inBounds(double, double) : boolean The class should have three constructors: 1. The default constructor should create a 1 x 1 square whose lower left corner is on the origin. 2. The second constructor takes two doubles, width and height, and creates a rectangle with one corner touching the origin, and the other corner touching the point (width, height). 3. The last constructor takes four coordinates; x1, y1, x2, and y2; for the lower left and upper right coordinates, (x1, Y) and (x2, y2). Error check the input to ensure that (x1,y1) is in fact to the lower left of (x2, y2), rather than the other way around. If the coordinates are wrong, switch them. It is also possible that neither coordinate is the lower left - you could be given a pair of upper left and lower right coordinates. In that case you can correct the coordinates by swapping y1 and y2, then proceeding to set the corner points normally. The area and perimeter methods should be self explanatory; they return doubles for the area and perimeter of the rectangle, respectively. distanceFromOrigin returns the distance between the lower left corner and the origin. Both should return a double. The final method, inBounds, takes x and y coordinates and determines whether that point is inside the rectangle, or on the perimeter. The method returns a boolean; true if the point is within the bounds of the rectangle, and false otherwise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!