Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named Triangle that extends GeometricObject (as shown below). The class should contain the following three private double data fields: side1, side2, side3

Design a class named Triangle that extends GeometricObject (as shown below). The class should contain the following three private double data fields: side1, side2, side3 with default values 1.0 to denote three sides of the triangle.

In addition, the class should have the following constructors and methods:

  1. A no-arg constructor that initializes all three sides to 0 .

  2. A constructor that creates a triangle with the specified side1, side2, and side3.

  3. The setter methods for three data fields.

  4. The getter methods for three data fields.

  5. A method named getPerimeter() that returns the perimeter of this triangle.

  6. A method named toString() that returns a string description for the triangle.

Write a test program that does the following tasks:

  1. Prompts the user to enter three sides of the triangle. The program creates a Triangle object with these sides. Prompt the user to enter a color and a Boolean value to indicate whether the triangle is filled. Use these two input values to set the data fields color and filled.

  2. Invoke the Triangle objects getPerimeter() and toString() methods.

public class GeometricObject {

private String color = "white";

private boolean filled;

private java.util.Date dateCreated;

/** Construct a default geometric object */

public GeometricObject() {

dateCreated = new java.util.Date();

}

/** Construct a geometric object with the specified color

* and filled value */

public GeometricObject(String Color, boolean filled) {

dateCreated = new java.util.Date();

this.color = color;

this.filled = filled;

}

/** Return color */

public String getColor() {

return color;

}

/** Set a new color */

public void setColor(String color) {

this.color = color;

}

/** Return filled. Since filled is boolean,

its get method is named isFilled */

public boolean isFilled() {

return filled;

}

/** Set a new filled */

public void setFilled(boolean filled) {

this.filled = filled;

}

/** Get dateCreated */

public java.util.Date getDateCreated() {

return dateCreated;

}

/** Return a string representation of this object */

public String toString() {

return "created on " + dateCreated + " color: " + color +

" and 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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

3. Describe the strategic training and development process.

Answered: 1 week ago

Question

10. Microsoft Corporation

Answered: 1 week ago

Question

4. EMC Corporation

Answered: 1 week ago