Question: Modify the class Shape so that it implements Cloneable and Comparable interfaces. The comparison should be solely based on the area of two shapes.


Modify the class Shape so that it implements Cloneable and Comparable interfaces.

Modify the class Shape so that it implements Cloneable and Comparable interfaces. The comparison should be solely based on the area of two shapes. Use the following method header: public int compareTo (Shape shp) Q2. [11 marks] Create a class named Hexagon that extends Shape. Assume that all six sides of a hexagon are of equal length. Create appropriate setter and getter method(s) and constructor(s), and override the toString method to return a string representation of all attribute values as well as the area and perimeter of a hexagon object. Write a test program that asks the use for the attributes of a Hexagon object (i.e., side length, color, and filled), creates that object, and then displays its state (side, color, area, etc.). Assume users enter valid inputs. Create a new object using the clone method and compare the two objects using the compareTo method. Hint: Add "throws CloneNotSupported Exception" to the header of the clone method as well as the main method in your test program. You will learn more about exception handling in next lecture and lab. Sample run Color: Red Filled (Yes/No)? No Side length: 5 First Hexagon Color: Red. Not filled. Side: 5.0. Area: 64.9519052838329. Perimeter: 30.0 Clonned Hexagon Color: Red. Not filled.

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 Programming Questions!