Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

resolve - 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+"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));
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...