Question: Exercise 4: A Rectangle made of Points 1. Create a new Java project and then create a new class called Point that represents a point
Exercise 4: 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 xy- plane as a pair of integer values (x,y) to represent a point using the screen coordinates; i.e. the screen's 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 x600 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 x600 and y 400 2. Proide a method called getDistance0 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 toString0 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 is Filled that evaluates to true when the rectangle is filled with the given color and false otherwise 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 Java's default values 5. 6. Add a method called getWidth0 and a method called getHeight0 to return the width and height 7. Provide a boolean method called isPortrait0 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. Povide 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
