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

I need help with the following Java exercise. Please make this simple and basic

ID: 3831948 • Letter: I

Question

I need help with the following Java exercise. Please make this simple and basic if possible.

Design a class named Triangle that extends SimpleGeometricObject. 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.

For the formula to compute the area of a triangle, see Programming Exercise 2.19. 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. SimpleGeometricObject.java and Exercise02_19.java have been provided.

Here is the SimpleGeometricObject code:

public class SimpleGeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;

/** Construct a default geometric object */
public SimpleGeometricObject() {
dateCreated = new java.util.Date();
}

/** Construct a geometric object with the specified color
* and filled value */
public SimpleGeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}

/** Return color */
public String getColor() {
return color;
}
public double getArea(){
   return 55;
}

/** 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;
}
}

Here is the code for Exercise 2.19 that gets the area of a triangle:

Explanation / Answer

import java.util.Scanner;

class Triangle extends SimpleGeometricObject {
double side1=1.0, side2=1.0, side3=1.0,area;
Triangle(){
double s = (side1 + side2 + side3) / 2;
area = Math.pow(s * (s - side1) * (s - side2) * (s - side3), 0.5);

}
Triangle(double x1,double y1,double x2,double y2,double x3,double y3){
side1 = Math.pow((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2), 0.5);
side2 = Math.pow((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3), 0.5);
side3 = Math.pow((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2), 0.5);

double s = (side1 + side2 + side3) / 2;
area = Math.pow(s * (s - side1) * (s - side2) * (s - side3), 0.5);
}
public double getArea(){
return area;
}
public double getPerimeter(){
return side1+side2+side3;
}
public String toString() {
return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
}
public static void main(String[] args) {
// Enter three points for a triangle
System.out.print("Enter three points for a triangle: ");
Scanner input = new Scanner(System.in);
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
String clr = input.next();
boolean bl = input.nextBoolean();

// Compute the length of the three sides
Triangle tg=new Triangle(x1,y1,x2,y2,x3,y3);
tg.setColor(clr);
tg.setFilled(bl);
System.out.println("The area of the triangle is " + tg.getArea());
System.out.println("The perimeter of the triangle is " + tg.getPerimeter());
System.out.println( tg.toString());
System.out.println( tg.getColor());
System.out.println( tg.isFilled());
}
}

//Run the file you will get the answers