Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces.

Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces.

Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables.

Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method getSide() for computing Octagon's side. Its area then can be computed according to the formula: area = (2 + 4/sqrt(2)) * side * side. Write a test program that creates an array of shapes consisting of several instances of Circ, Rect, and Octagon and displays their area and perimeter. Create a new Octagon object by using the clone() method and compare the two objects using the compareTo() method. Include in your test program the method that returns the largest object in an array of objects. The method header is public static Object max(Object[] a) All the objects are assumed to be the instances of the Comparable interface. Apply the method max to your array of shapes to find and display the maximum one. Therefore, your project should include the following java classes: Circ, Rect, Shape, Octagon, and ShapeMaster (the main class containing the main() method). Redesign the first two classes to implement the Comparable and Cloneable interfaces.

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions