Could not use non-static method from a static location- Compiler Error
807600Jul 16 2007 — edited Jul 16 2007Hello everyone, I am new to this site and I just needed a little help with my code to finish it. Im not sure why I get the error stated above, but here is my code(s) from both classes.
public class Triangle
{
private int base;
private int height;
private int numOfTriangles = 0;
double calc;
public void zeroReturn()
{
}
public void twoReturn(String base, String height)
{
System.out.println("Triangle base: " + base + " inches.");
System.out.println("Triangle height: " + height + " inches.");
}
public void areaReturn()
{
calc = base*height/2;
System.out.println("\nThe area of this triangle is: "+ calc);
numOfTriangles++;
System.out.println("\nThere are a total of " + numOfTriangles + " triangles entered.");
}
}
And the second prgram class:
public class TriangleProgram
{
public static void main(String[] args)
{
Triangle firstTriangle = new Triangle();
TrianglesecondTriangle = new Triangle();
Triangle thirdTriangle = new Triangle();
System.out.println("Triangle One\n");
firstTriangle.twoReturn("23","32");
System.out.println("\n");
System.out.println("Triangle Two\n");
secondTriangle.twoReturn("12","21");
System.out.println("\n");
System.out.println("Triangle Three\n");
thirdTriangle.twoReturn("34", "43");
System.out.println("\n");
Triangle.areaReturn();
}
}
Basically what I am trying to do is Write an object file named Triangle.java to use in conjunction with a program file named TriangleProgram.java. The instance variables base and height should have to be private modifiers and be non static. The Triangle class should also contain an instance variable named numOfTriangles to count the number of Triangleobjects instantiated. The Triangleclass should have two constructors, a constructor to handle zero parameter triangles and a constructor with two parameters to handle triangle objects that receive base and height arguments. The Triangle class should use as many methods as needed to calculate and output the dimensions of each triangle object, the area of each triangle object, the sum of the area of all triangle objects and the number of triangle objects instantiated.
Any help or guidance would be greatly appreciated. Thank you.
Message was edited by:
beatjunkie