Purchase Solution

Java Problem Implementing Cloneable and Comparable Interfaces

Not what you're looking for?

Ask Custom Question

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

Purchase this Solution

Solution Summary

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

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

C# variables and classes

This quiz contains questions about C# classes and variables.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.