I'm working on a program that calls on a method from another class, and I can't seem to get past that road bump. The example I'm using simply sets a variable in the main method equal to the other class, and the major error I'm getting in my own program is that the symbol I'm using can't be found - I've also looked at other similar questions on here, but I can't wrap my head around on how to use the answers in my own program.
Here a portion of my main method, called MyTriangle:
do
{
System.out.print ("Enter the first of a triangle: ");
side1 = scan.nextDouble();
System.out.print ("Enter the second side of a triangle: ");
side2 = scan.nextDouble();
System.out.print ("Enter the third side of a triangle: ");
side3 = scan.nextDouble();
validity = isValid (side1, side2, side3);
if (validity == true)
{
System.out.println ("Area of the triangle is " + area);
}
if (validity == false)
{
System.out.println ("Invalid input");
}
System.out.print ("\nContinue? <y/n> ");
end = scan.next();
} while (!end.equalsIgnoreCase("n"));
And here's a portion of my class TestMyTriangle:
public class TestMyTriangle
{
public static double area (double side1, double side2, double side3)
{
double resultArea = 0;
double sum = 0;
sum = ((side1 + side2 + side3) / 2);
resultArea = Math.sqrt(sum * ((sum - side1) * (sum - side2) * (sum -side3)));
return resultArea;
}
}
The way I'm invoking TestMyTriangle is identical to the example I'm using, but it's still not working. If anyone can help me see what I'm missing, I would appreciate it.