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

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

  • Three double data fields named side1, side2, and side3 with default values 0 to denote three sides of the triangle (6 points).
  • A no-arg constructor that creates a default triangle. (6 points)
  • A constructor that creates a triangle with the specified side1, side2, side3, and the String color, and boolean filled. Make sure you use the super() method. (16 points)
  • The accessor methods for all five data fields used for the non-def constructor. (10 points)
  • A method named getArea() that returns the area of this triangle. (8 points)
  • A method named getPerimeter() that returns the perimeter of this triangle. (8 points)
  • A method named toString() that returns a string description for the triangle. (6 points)

For the formula to compute the area of a triangle, see Exercise 5.19. The toString() method is implemented as follows:

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

Implement the class:

2- Write a test program TestTriangle.java that creates a Triangle object:

  • with sides 1, 1.5, 1
  • color = yellow
  • filled = true (10 points)
  • displays its area (2.5 points)
  • displays its perimeter(2.5 points)
  • displays its color (2.5 points)
  • displays whether it is filled or not (2.5 points)

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!