Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following class definitions abstract class Shapet protected Point p; //top-left corner public Shape) p new Point) 1 public Shape(int x, int y) {
Consider the following class definitions abstract class Shapet protected Point p; //top-left corner public Shape) p new Point) 1 public Shape(int x, int y) { p new point (x,y); } public String toString() { return string . format("%d", perimeter()); } public abstract int perimeterO; class Circle extends Shape [ private int radius; public circle) public Circle(int x, int y, int r) f super(x,y); public int perimeter) return (int) (Math.PIradius); class Rectangle extends Shape f private int width, height; public Rectangle th public Rectangle(int x, int y, int w, int h)t super(x,y); widthW; height h; public int perimeter) 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 Rectanglei new Rectangle(2e, 38, 48, 58); System.out.println(rl) 188 Answer (penalty regime: 0 %) 1 abstract class Shape implements Comparable
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started