Modify the class Shape so that it implements Cloneable and Comparable interfaces. The comparison should be...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Required a. Calculate the change in cash and cash equivalents that occurred during the current year. b. Prepare a statement of cash flows using the indirect method. a. Change in Cash during the...
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
An investor creates an investment portfolio from stock A and stock B where she invests 0.5 of her wealth in stock A and 0.5 of her wealth in stock B. Stock A has a beta of 1.39 and stock B has a beta...
-
If f and are the functions whose graphs are shown, let u(x) = f(g (x)), v(x) = g(f (x)), and w(x) = g(g (x)). Find each derivative, if it exists. If it does not exist, explain why. (a) u'(1) (b)...
-
Treasure Salvors and the State of Florida entered into a series of four annual contracts governing the salvage of the Nuestra Senora de Atocha. The Atocha is a Spanish galleon that sank in 1622,...
-
Maurice Turner, the owner of a newsletter for managers of hotels and restaurants, has prepared the following condensed amounts from his companys financial statements for 20x6: Given these figures,...
-
Moss Exports is having a bad year. Net income is only $60,000. Also, two important overseas customers are falling behind in their payments to Moss, and Mosss accounts receivable are ballooning. The...
-
early in 2012 dobbs corporation engaged kiner ,inc to design and construct a compleate modernization of dobbs manufacturing facility .construction was begun on june 1,2012 and was completed on...
-
A custom guitar shop sells two types of guitars electric and acoustic The creation process of each guitar is broken into three parts building the base guitar applying the finish paint and adding...
-
Peter Inc. of Cebu Ltd. has decided to institute a pilot activity-based costing project in its five-person purchasing department. Annual departmental costs are P473,500. Because finding the best...
-
Find the limit and explain why it doesn't exist. lim 2x 4 (x,4)-> (0,0) X4 +242
-
Directions: you must answer ONE the questions below by the deadline. Your post must be 8 sentences or more. Questions: What are the financial implications related to the key ideas that are discussed...
-
The Sheriff's Department of Polk County Florida, run by Sheriff Grady Judd, has announced the arrest of three deputies for their involvement in evidence tampering. This egregious act did outrage the...
-
4.1 Key performance indicators Identify at least 2 key performance indicators a clothing business will use in its business. Define what they are and explain how they will assist the clothing business...
-
3. Nikki's "Nick-Nacks" has the following ATCF's for a projectoffering 12% over the next 5 years: Year 1, $345,678 Year 2,$398,990 Year 3, $ 523,934 Year 4, $575,349 Year 5, $602,497 Herinitial exp...
-
Tarick Toys Company manufactures video game consoles and accounts for product costs using process costing. The following information is available regarding its June inventories. The following...
-
Purchase and Disposal of Operating Asset and Effects on Statement of Cash Flows On January 1, 2008, Castlewood Company purchased some machinery for its production line for $104,000. Using an...
-
Depreciation as a Tax Shield The term tax shield refers to the amount of income tax saved by deducting depreciation for income tax purposes. Assume that Rummy Company is considering the purchase of...
-
Lump-Sum Purchase of Assets and Subsequent Events Dixon Manufacturing purchased, for cash, three large pieces of equipment. Based on recent sales of similar equipment, the fair market values are as...
Study smarter with the SolutionInn App