Question: My Program will not compile. For the Triangle.java part of the program and the constructor listed below, getting the following compile error: implicit super constructor
My Program will not compile. For the Triangle.java part of the program and the constructor listed below, getting the following compile error: "implicit super constructor GeometricObject() is undefined. Must explicitly envoke another constructor." What I have completed and the directions are listed below.
public Triangle(double side1, double side2, double side3)
{
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}

import java.util.Scanner;
public class TriangleObject {
static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
input = new Scanner(System.in);
System.out.println("Enter the sides of the triangle");
double sideA = input.nextDouble();
double sideB = input.nextDouble();
double sideC = input.nextDouble();
String st = input.next();
Boolean but = input.nextBoolean();
//Object for the Triangle
Triangle triangle = new Triangle(sideA, sideB, sideC);
//Set color property
triangle.setColor(st);
//Set filled property as true
triangle.setFilled(but);
//Display triangle object details
System.out.println(triangle);
System.out.println("The area is " + triangle.getArea());
System.out.println("The perimeter is " + triangle.getPerimeter());
System.out.println(triangle);
}
}
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
//default constructor
protected GeometricObject()
{
}
protected GeometricObject(String color, boolean filled)
{
this.color = color;
this.filled = filled;
}
//Get Method
public String getColor()
{
return color;
}
//Set Method
public void setColor(String color)
{
this.color = color;
System.out.println("The color to fill " + "the triangle is: " + color);
}
//Get Method for filled
public boolean isFilled()
{
return filled;
}
//Set Method for filled
public void setFilled(boolean filled)
{
this.filled = filled;
System.out.println("Whether the Triangle is " + "filled with color? " + filled);
}
public abstract double getArea();
public abstract double getPerimeter();
}
public class Triangle extends GeometricObject {
private double side1 = 1.0;
private double side2 = 1.0;
private double side3 = 1.0;
public Triangle()
{
side1 = 1.0;
side2 = 1.0;
side3 = 1.0;
}
//Constructor
public Triangle(double side1, double side2, double side3)
{
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
//Implement the abstract method to find Area in GeometricObject
public double getArea()
{
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
public double getPerimeter()
{
return side1 + side2 + side3;
}
public String toString()
{
return "Triangle: Side 1 = " + side1 + " Side 2 = " + side2 + " Side 3 = " + side3;
}
}
13.1 (Triangle class) Design a new Triangle class that extends the abstract Geometricobject class. Draw the UML diagram for the classes Triangle and Geometricobject and then implement the Triangle class. 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
