I got an error from first row of the code says GeometricObject Cannot be resolved to a type error how can ? fix it ? What is the problem about ?
class Triangle extends GeometricObject implements Comparable<Triangle>
{
private int a;
private int b;
private int c;
private String color;
private boolean isFilled;
public Triangle(int a, int b, int c, String color, boolean filled){
this.a = a;
this.b = b;
this.c = c;
this.color = color;
this.isFilled = filled;
}
public int getA(){return a;}
public int getB(){return b;}
public int getC(){return c;}
public String getColor(){return color;}
public boolean getIsFilled(){return isFilled;}
public double getPerimeter(){
return (a + b + c) ;
}
public double getArea(){
double s = (a + b + c)/2;
return Math.round(Math.sqrt(s*(s-a)*(s-b)*(s-c)));
}
public int compareTo(Triangle tri){
if(getArea()==tri.getArea())
return 0;
else if(getArea() > tri.getArea())
return 1;
else
return -1;
}
public boolean equals(Triangle tri){
if(a==tri.getA() && b == tri.getB() && c== tri.getC() && color.equals(tri.getColor()) && isFilled == tri.getIsFilled())
return true;
return false;
}
public String toString(){
return "Triangle Color: "+color+"isFilled: "+isFilled+" Side A: "+a+"Side B: "+b+"Side C: "+c+"Perimeter: "+getPerimeter()
+"Area: "+getArea()+"
";
}
}
public class TriangleTest
{
public static void main(String[] args)
{
java.util.ArrayList<Triangle> list = new java.util.ArrayList<Triangle>();
Triangle t1 = new Triangle(10, 10, 10, "Black", false);
Triangle t2 = new Triangle(12, 12, 12, "Green", true);
Triangle t3 = new Triangle(12, 12, 12, "Green", true);
Triangle t4 = new Triangle(20, 20, 20, "Blue", false);
Triangle t5 = new Triangle(8, 8, 8, "Yellow", true);
list.add(t1);
list.add(t2);
list.add(t3);
list.add(t4);
list.add(t5);
System.out.println("############# Displaying Triangle Details ################
");
list.forEach(tri -> System.out.println(tri));
System.out.println("############# Displaying Triangle Details after sorting ################
");
java.util.Collections.sort(list);
list.forEach(tri -> System.out.println(tri));
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…