Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

What are some of the features of the Unified Process (UP)?

Answered: 1 week ago

Question

How can personnel best provide services for a group of 25 clients?

Answered: 1 week ago