Share
Explore BrainMass

Java Problem Implementing Cloneable and Comparable Interfaces

I'm supposed to write a class Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. The octagons sides are all of equal size. The area 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.

The project should include the following classes: Circ, Rect, Shape, Octagon, and Test (the main class containing the main() method). Redesign the first two classes to implement the Comparable and Cloneable interfaces.

The circ, shape and rect classes are attached and done already. (workable)

Thank you

Attachments

Solution Summary

The expert examines Java problems for implementing cloneable and comparable interfaces.

$2.19