简体   繁体   中英

Java Eclipse IDE Type Error Resolving Error

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+"\tisFilled: "+isFilled+"\t Side A: "+a+"\tSide B: "+b+"\tSide C: "+c+"\tPerimeter: "+getPerimeter()
               +"\tArea: "+getArea()+"\n";
    }
}
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("\t\t\t\t############# Displaying Triangle Details ################\n");
        list.forEach(tri -> System.out.println(tri));
        System.out.println("\t\t\t############# Displaying Triangle Details after sorting ################\n");      
        java.util.Collections.sort(list);
        list.forEach(tri -> System.out.println(tri));
    }
}

That means you haven't imported any "GeometricObject" class.

If you using and external library, check if it's properly imported. If you are using an abstract class which you made, then just import it.

PS: try to write cleaner problem descriptions please, there is no need to spam:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM