2013-10-19 39 views
0

由於某些原因,我一直在爲找不到符號錯誤,因爲它們是Triangle.is_equilateral,Triangle.is_isosceles和Triangle.is_scalene。在我的Triangle類中找不到符號錯誤

這裏是三角類:

public class Triangle 
{ 
    private int s1; 
    private int s2; 
    private int s3; 

    public Triangle (int num1, int num2, int num3) 
{ 
     s1= num1; 
     s2= num2; 
     s3= num3; 
} 

    public String toString() 
    { 
    return (s1 + " " + s2 + " " + s3); 
    } 

    public boolean is_equilateral(){ 
if(s1==s2 && s2==s3 && s3==s1) 
    { 
    return Triangle.is_equilateral; 
    } 
else 
{ 
    return false; 
} 
} 

    public boolean is_isosceles(){ 
if((s1==s2)||(s2==s3)||(s3==s1)) 
{ 
    return Triangle.is_isosceles; 
} 
else 
{ 
    return false; 
} 
} 

    public boolean is_scalene(){ 
if(s1!=s2 && s2!=s3 && s3!=s1) 
{ 
    return Triangle.is_scalene; 
} 
else 
{ 
    return false; 
} 
} 


    } 

,這裏是測試程序:

public static void main (String[] args) { 

     Scanner console = new Scanner(System.in); 
     int num1; 
     int num2; 
     int num3; 
     String another; 
     do 
     { 
     System.out.println("Enter the sides of the triangle: "); 
     num1 = console.nextInt(); 
     num2 = console.nextInt(); 
     num3 = console.nextInt(); 

     Triangle myTriangle = new Triangle (num1, num2, num3); 


     System.out.println(myTriangle.toString() + " triangle:"); 

     //check the isosceles 
     if (myTriangle.is_isosceles()) 
      System.out.println("\tIt is isosceles"); 
     else 
      System.out.println("\tIt is not isosceles"); 

     //check the equilateral 
     if (myTriangle.is_equilateral()) 
      System.out.println("\tIt is equilateral"); 
     else 
      System.out.println("\tIt is not a equilateral"); 

     //check the scalene 
     if (myTriangle.is_scalene()) 
      System.out.println("\tIt is scalene"); 
     else 
      System.out.println("\tIt is not scalene"); 


     System.out.println(); 
     System.out.print("Check another Triangle (y/n)? "); 
     another = console.next(); 

    } while (another.equalsIgnoreCase("y")); 


    } // method main 

} // class Assignment5 

感謝您的幫助。非常感謝。

+0

NVM,我是個白癡。 –

+0

[在我的三角形類中找不到符號錯誤]的可能重複](http://stackoverflow.com/questions/19461214/cannot-find-symbol-error-in-my-triangle-class) – demongolem

回答

0

您還沒有聲明的成員is_equilateralis_isoscelesis_scaleneTriangle類 裏面你需要添加它們:
private bool is_equilateral;
private bool is_isosceles;
private bool is_scalene;