Question: Consider the following class definitions abstract class Shape protected Point p; //top-left corner public shape() { p = new Point(); } public Shape(int x, int

 Consider the following class definitions abstract class Shape protected Point p;

Consider the following class definitions abstract class Shape protected Point p; //top-left corner public shape() { p = new Point(); } public Shape(int x, int y) P new Point(x,y); public string toString() { return string , format ("%d", perimeter()); } public abstract int perimeter); class Circle extends Shape [ private int radius; public Circle) public Circle(int x, int y, int r) t super(x,y); radius -r; public int perimeter) return (int) (Math.PI 2radius); class Rectangle extends Shape ( private int width, height; public Rectangle) t public Rectangle(int x, int y, int w, int h) super(x,y); width - ; height h; public int perimeter) t return (width height) 2; You are required to modify the Shape class and implement the Comparable interface. You will need to override the compareTo (Shape s) method. The comparison is based on the perimeter of shapes. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified Shape. Write the Shape class in the answer box below assuming that the Rectangle and Circle have been done for you. For example Test Result Rectangle rl new Rectangle (20, 30, 40, 50); System.out.println(r1); 188 Answer (penalty regime: 0 %) 1 abstract class Shape implements Comparable protected Point p; //top-left corner public Shape) p new Point); public Shape (int x, int y) p new Point(x,y); 18 public String tostring) 12 13 14 15 16 17 return string.format("%d", perimeter()); public abstract int perimeter)

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!