Question: A Rectangle made of Points 1. Create a new Java project and then create a new class called Point that represents a point on the
A Rectangle made of Points
1. Create a new Java project and then create a new class called Point that represents a point on the xyplane as a pair of integer values (x,y) to represent a point using the screen coordinates; i.e. the screens top-left corner is the origin. Provide getter methods and a no-arg constructor that initializes the default values of x and y to positive random values satisfying x?600 and y?400 (Hint: use SecureRandom- as in Lab5). Also include a 2-arg constructor that initializes x and y to values passed as arguments. Ensure that the x and y values are all positive and that x?600 and y?400 .
2. Provide a method called getDistance() that takes a Point as a parameter and return the distance between the current point and the parameter. Signature is: public double getDistance(Point aPoint).
3. Provide a toString() method that returns the current Point as a pair in the format (x,y).
4. In the same project create another class called Rectangle that represents a typical rectangle as two Points representing the top-left corner and the bottom-right corner of the rectangle (i.e. a Rectangle is composed of two Points or has two points). Include a third String attribute that represents the color of the rectangle, and a boolean attribute called isFilled that evaluates to true when the rectangle is filled with the given color and false otherwise.
5. Generate setters and getters for the above attributes. Also generate a parameterized constructor to initialize the attributes using the parameter values. Also include a no-arg constructor that sets topLeft and bottomRight to random Points and other attributes to Javas default values.
6. Add a method called getWidth() and a method called getHeight() to return the width and height.
7. Provide a boolean method called isPortrait() to return true if the width is smaller than the height and false otherwise.
8. Provide a method to return the area of a rectangle.
9. Provide a toString() method that returns a string representing details of the current rectangle and its area, whether it is portrait or land scape.
10. Provide a method that compares the area of the current rectangle with that of another rectangle; it returns 1 if the current rectangle is larger, -1 if the current rectangle is smaller, and 0 if both are equal. The method signature is: public int compareTo(Rectangle other).
11. Create a RectangleTest class in which you demonstrate features of your Rectangle and Point classes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
