2

I've done this little program which tries to construct triangles and calculates the surface for homework and I tested it in Eclipse but when I try to upload it to our system I get 6 errors, all of the same type:

/test/src/math.test/TestTriangleFunctionPublic.java:4: error: cannot find symbol import math.NotATriangleException; ^ symbol: class NotATriangleException

/test/src/math.test/TestTriangleFunctionPublic.java:5: error: cannot find symbol import math.Triangle; ^ symbol: class Triangle location: package math

/test/src/math.test/TestTriangleFunctionPublic.java:45: error: cannot find symbol actual = Triangle.calculateArea(a, b, c); ^ symbol: variable Triangle location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:46: error: cannot find symbol } catch (NotATriangleException e1) { ^ symbol: class NotATriangleException location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:56: error: cannot find symbol actual = Triangle.calculateArea(a, b, c); ^ symbol: variable Triangle location: class TestTriangleFunctionPublic

/test/src/math.test/TestTriangleFunctionPublic.java:57: error: cannot find symbol } catch (NotATriangleException e) { ^ symbol: class NotATriangleException location: class TestTriangleFunctionPublic

This are the two classes:

package math;

public class Triangle {
    static double s;
    double surface = 0;
    static double a;
    static double b;
    static double c;

    public double calculateArea(double a, double b, double c) throws NotATriangleException{
        if (a<= 0.0 || b <= 0.0 || c <= 0.0){
            throw new NotATriangleException("Cannot construct Triangle!");
        }
        else if( (a+b)<=c && (a+c)<=b && (b+c)<=a){
            throw new NotATriangleException("Cannot construct Triangle!"); 
        } 

        else {
            s = ((a + b + c)/2);
            surface = Math.sqrt(s * (s - a) * (s - b) * (s - c));
            return surface;
        }

    }
    public double getErgebnis (){
        return surface;
    }
}

and the Exception class:

package math;

@SuppressWarnings("serial")
public class NotATriangleException extends Exception {
    public NotATriangleException(String message) {
        super(message);
    }
    public NotATriangleException(String message,Throwable throwable) {
        super(message, throwable);
    }
}

I'm disappointed because I can't figure out what's wrong!

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Henrik Peters
  • 19
  • 1
  • 5

1 Answers1

2

You have a class called TestTriangleFunctionPublic. I think you had this class in the same math package in Eclipse, but when you uploaded it, you changed the location to a directory called math.test.

Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • +1 The directory should be `math` not `math.test` No wonder it cannot find the class. – Peter Lawrey Jan 20 '13 at 21:35
  • The TestTriangleFunctionPublic class was not part of the homework. I think it's created by the programm that tests and compiles our homework. Thanks for the fast help but I have to ask a professor what the problem was. – Henrik Peters Jan 21 '13 at 13:41