Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with Java program? Task 1 The GeometricObject Abstract Class First, let us make a simple abstract class titled GeometricObject. A GeometricObject should include:

Please help with Java program?

Task 1 The GeometricObject Abstract Class

First, let us make a simple abstract class titled GeometricObject. A GeometricObject should include: a side length attribute and an area attribute, a ToString method that returns both of the class variables AND the name of the class (which should be GeometricObject). It SHOULD NOT include any type of constructor. The variables should be made protected, but the methods should be public.

Task 2 Implementing the Comparable and Cloneable Interfaces

Now implement the two interfaces by adding them to the class header.

  • For Java: GeometricObject implements Comparable, Cloneable

We will also need to add two methods, one that comes from the Comparable class and one that comes from the Cloneable class. So we will override both the CompareTo and Clone methods so that they will compare two GeometricObjects and clone, or create a new, GeometricObject from an existing one.

For the comparison, we will compare both of our objects values for side length and area. If both the side length and area are the same, then the method should return zero (0), otherwise if the values were greater than the originals values return negative one (-1), or return one (1) if the values were less than the originals values.

For the clone method, it should return a new object with the same values as the original object it was cloned from.

Task 3 The Octagon Subclass

Next is to create a class Octagon that inherits from our abstract GeometricObject class. This means it will also inherit the interface methods along with the class variables and any other defined methods or variables from GeometricObject. So the only thing we need to add is a constructor. The constructor should be a default constructor that sets the side length to eight (8) and calculates the area based on the side length. Also include an overloaded constructor that sets the side length to some input value, and uses that input value to calculate the area. Use the formula below for the area:

Area = 2(1 + 2) * side^2

Task 4 The Driver (Main Program)

Let us now use our classes by creating objects. Create an Octagon and clone it using the clone method from above. Now compare both the clone and the original using the compare method from above. Finally, print out the data stored in each object using their ToString methods and print out the result of the comparison (DO NOT explicitly call the ToString method when doing so). Below is some possible sample output (note: simply means, there exists):

Some Sample Output:

Octagon 1s side length: 8 and area is: 309.02

Octagon 2s side length: 8 and area is: 309.02

The 2 geometric objects are the same.

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_2

Step: 3

blur-text-image_3

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions