Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions