Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

( The Triangle class ) Design a class named Triangle that extends GeometricObjec

ID: 3723919 • Letter: #

Question

(The Triangle class) Design a class named Triangle that extends GeometricObject. (the GeometricObject class is included in the zip folder). 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 following is the formula to compute the area of a triangle:

The toString() method is implemented as follows: return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;

Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.

s-(sidel side2 side3)/2 area = Vs(s-side lXs-side2)($-side3)

Explanation / Answer

The question refers to a class GeometricObject which you have not provided in the question. Based on the description given I have created the Triangle class. Use it along with your GeometricObject class. In order to write the test class I will need the GeometricObject class as well.. otherwise I can't compile the code. The constructors in Triangle class will need to be slightly modified to call the constructor of GeometricObject. Please provide the GeometricObject code and I'll help you integrate the Triangle class.


public class Triangle extends GeometricObject {
private double side1, side2, side3;

public Triangle()
{
super();
side1 = side2 = side3 = 1.0;
}

public Triangle(double s1, double s2, double s3)
{
side1 = s1;
side2 = s2;
side3 = s3;
}

public double getSide1() {
return side1;
}

public double getSide2() {
return side2;
}

public double getSide3() {
return side3;
}

public double getArea()
{
double s = (side1 + side2 + side3) /2;
double area = Math.sqrt(s * (s-side1) * (s-side2) * (s-side3));
return area;
}

public double getPerimeter()
{
return side1 + side2 + side3;
}

public String toString()
{
return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
}
}