Question: *********************************IN JAVA************************************************ Rewrite the provided Rectangle class to extend GeometricObject and implement the Comparable interface. Override the equals method of the Object class. Two Rectangle

*********************************IN JAVA************************************************

Rewrite the provided Rectangle class to extend GeometricObject and implement the Comparable interface. Override the equals method of the Object class.

Two Rectangle objects are equal if their areas are the same.

Implement the compareTo to be consistent with equals method.

The compareTo method will return 0, if two rectangle are eqauls

The compareTo method return 1 , if the area of rectangle1 is bigger than the area of rectangle2

The compareTo method return -1, if the area of rectangle2 is bigger than the area of rectangle1

Sample Run:

Note:

The first two numbers are the width and height of the first rectangle followed by the width and height of the second rectangle follow by "==" for equals or ">=<" for compareTo method.

The width and height of a rectangle is a positive value and the default value is 1.

For zero and negative numbers use the default values.

Input 2 2

0.5 8

==

Output

true

Input 2 2

0.5 8

>=<

Output

0

Input 2 3

0.5 8

>=<

Output

1

*******Use the following class driver with no modifications to it!********

import java.util.*; import java.lang.*; import java.io.*;

abstract class GeometricObject { //assign default values private String color = "white"; private boolean filled; private java.util.Date dateCreated;

/** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; }

/** Return color */ public String getColor() { return color; }

/** Set a new color */ public void setColor(String color) { this.color = color; }

/** Return filled. Since filled is boolean, * the get method is named isFilled */ public boolean isFilled() { return filled; }

/** Set a new filled */ public void setFilled(boolean filled) { this.filled = filled; }

/** Get dateCreated */ public java.util.Date getDateCreated() { return dateCreated; }

@Override public String toString() { return "created on " + dateCreated + " color: " + color + " and filled: " + filled; }

/** Abstract method getArea */ public abstract double getArea();

/** Abstract method getPerimeter */ public abstract double getPerimeter(); }

**********HERE'S THE MAIN DRIVER, NO MODIFCATIONS HERE EITHER***********

class DriverMain{

public static void main(String args[]){

Scanner input = new Scanner(System.in);

double w1 = input.nextDouble();

double h1 = input.nextDouble();

double w2 = input.nextDouble();

double h2 = input.nextDouble();

String s = input.next();

Rectangle rectangle1 = new Rectangle(w1, h1);

Rectangle rectangle2 = new Rectangle(w2, h2);

if(s.equals("=="))

System.out.print(rectangle1.equals(rectangle2)) ;

else if(s.equals(">=<"))

System.out.print(rectangle1.compareTo(rectangle2));

else

System.out.print("Invalid");

}

}

***********************************************************************************

---And use the following class that was refered to in main----

class Rectangle { private double width; private double height; public Rectangle() { }

public Rectangle(double width, double height) { this.width = width; this.height = height; }

/** Return width */ public double getWidth() { return width; }

/** Set a new width */ public void setWidth(double width) { this.width = width; }

/** Return height */ public double getHeight() { return height; } /** Set a new height */ public void setHeight(double height) { this.height = height; } }

***********************************************************************************************************************

Leaving comments in the code would be much appreciated to help me understand the code more!

PLEASE follow assignment instructions as I am having trouble understanding everything completely!

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!