Question: Design a class named Triangle that extends GeometricObject . The class contains: Three double data fields named side1 , side2 , and side3 with default

Design a class named Triangle that extends GeometricObject. The class contains:

Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.

A no-arg constructor that creates a default triangle.

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

The accessor methods for all three data fields.

A method named getArea() that returns the area of this triangle.

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

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

The toString() method is implemented as follows:

return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;

The program should then create a Triangle object with these sides and set the colour and filled properties using the input. The program should display the area, perimeter, colour, true or false to indicate whether it is filled or not, and the string description for the triangle.

Sample runs:

Enter three sides: 1 2 3

Invalid triangle. Enter three sides: 2 3 1

Invalid triangle. Enter three sides: 3 1 2

Invalid triangle. Enter three sides: 3 4 5

Enter the color: yellow

yellow is an invalid color. Enter the color: blue

Enter a boolean value for filled: 0

0 is an invalid boolean value. Enter the boolean value for filled: 1

1 is an invalid boolean value. Enter the boolean value for filled: False

The area is 6.0

The perimeter is 12.0

The color is blue

Is filled? false

Triangle: side1 = 3.0 side2 = 4.0 side3 = 5.0

Enter three sides: 3 4 5

Enter the color: red

Enter a boolean value for filled: true

The area is 6.0

The perimeter is 12.0

The color is red

Is filled? true

Triangle: side1 = 3.0 side2 = 4.0 side3 = 5.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!