Question: Using the programming language Java, create a class for Triangle objects. This Triangle class should inherit from a Shape class and implement its own getArea()
Using the programming language Java, create a class for Triangle objects. This Triangle class should inherit from a Shape class and implement its own getArea() and getPerimeter() methods. (Triangle extends Shape). Include a constructor that expects three double values for the triangle's sides. Pass a Triangle object to this method to display the data. Note that the methods for class Shape are abstract. Create a program to test your Triangle class, and include a method that takes a Shape object as a parameter. The output includes the input of three double variables, the area, and the perimeter. Sample output is shown below:
Enter the 3 sides of the triangle
2 3 3.6
Area = 2.999983
Perimeter = 8.600000
Hint: To find a triangle's area, use the following formula (given three sides):
public double getArea(){
double s = (side1 + side2 + side3)/2;
return Math.sqrt(s* (s-side1)*(s-side2)*(s-side3));
}
Note: Attach a zipper folder that includes all the required Java files.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
