Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read instructions very carefully. Java programming language please. Q1 (15 Marks) Create a class named Hexagonthat extends shape class and implements the Cloneableand Comparableinterfaces. The

Read instructions very carefully. Java programming language please. image text in transcribed
image text in transcribed
Q1 (15 Marks) Create a class named Hexagonthat extends shape class and implements the Cloneableand Comparableinterfaces. The comparison should be based on the area of two shapes. Use the following method header: public int compareTo(Shape shp) 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 user for the attributes of a Hexagonobject (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 compareTomethod. After running the compareTol) method, modify one the parameters of the cloned object (for example r2.height) then run the compareTo to check the outcome. Hint: Add "throws Clone NotSupportedException" to the header of the clonemethod as well as the mainmethod in your test program. You will learn more about exception handling in next lecture and lab. Sample run Color: Green Filled (Yes/No)? n Side: 5 First Hexagon color: Green. Not filled. Side: 5.8. Area : 64.9519852838329. Perimeter : 30.0 Clonned Hexagon color: Green. Not filled. side: 5.e. Area: 64.9519052838329. Perimeter: 30. Both Hexagon are identical. Modify the clonned Rec color: Green. Not filled. Side : 15.0. Area: 584.5671475544962. Perimeter: 90. the two Hexagon are different

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions