Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java prgram use eclipes, The program code for the class GeometricObject is provided in Test1.zip and should be made part of the package. Complete the

java prgram use eclipes,

The program code for the class GeometricObject is provided in Test1.zip and should be made part of the package. Complete the following two classes and tester described below. This part is open book, open notes, open API and open Internet.

Create a class named RegularOctagon that extends GeometricObject. The eight sides of a regular octagon are of equal size.

RegularOctagon has one instance variable (-side: double).

There are three constructors:

A no-args constructor that creates a default RegularOctagon with side=1.0. The color and filled values are default.

A one argument constructor that creates a RegularOctagon with the given side. The color and filled values are default.

A three argument constructor that creates a RegularOctagon with the given color, filled and side values.

The methods are:

The getter and setter for side.

that overrides the toString() method in the superclass to display the color, filled and side instance variables. The overriding toString() method must call toString() in the superclass to display the color and filled values.

+getArea(): double that computes and returns the area. The formula for the area of a regular octagon is: area = 2 * (1 + sqrt(2)) * (side2)

+getPerimeter(): double that computes and returns the perimeter. The formula for the perimeter of a regular octagon is: perimeter = 8 * side

Create a class named OctagonalPrism that extends RegularOctagon.

OctagonalPrism has one instance variable (-height: double).

There are three constructors:

A no-args constructor that creates a default OctagonalPrism with height=1.0. The color, filled and side values are default.

A one argument constructor that creates an OctagonalPrism with the given height. The color, filled and side values are default.

A four argument constructor that creates an OctagonalPrism with the given color, filled, side and height values.

The methods are:

The getter and setter for height.

that overrides the toString() method in the superclass to display the color, filled, side and height instance variables. The overriding toString() method must call toString() in the superclass to display the color, filled and side values.

+getVolume(): double that computes and returns the volume. Use the getArea() method in the superclass to compute the volume. The formula for the volume of the octagonal prism is: volume = 2 * (1 + sqrt(2)) * (side2) * height

Create a class TestGeometricObject that does the following tasks:

The console output of the program should be readable and similar to the screenshot below. You are allowed to rewrite the toString() methods in all classes including the GeometricObject class.

import java.util.Date;

public class GeometricObject {

private String color;

private boolean filled;

private Date dateCreated;

public GeometricObject(){

this("white", false);

}

/**

* @param color

* @param filled

*/

public GeometricObject(String color, boolean filled) {

this.color = color;

this.filled = filled;

this.dateCreated = new Date();

}

/**

* @return the color

*/

public String getColor() {

return color;

}

/**

* @param color the color to set

*/

public void setColor(String color) {

this.color = color;

}

/**

* @return the filled

*/

public boolean isFilled() {

return filled;

}

/**

* @param filled the filled to set

*/

public void setFilled(boolean filled) {

this.filled = filled;

}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

return "GeometricObject [color=" + color + ", filled=" + filled + "]";

}

}

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: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

=+ a. What is the per-worker production function?

Answered: 1 week ago