So in the code below I create an instance of my own triangle class and use one of its methods. The thing is I use one of my triangle classes methods in a method other the main method of my main program so I'm thinking it can't access it?
anyway heres the code for my triangle class
import java.util.Scanner; public class QudratullahMommandi_Triangle_06 { Scanner keyboard = new Scanner(System.in); private double side1; private double side2; private double side3; public QudratullahMommandi_Triangle_06() { side1 = 0; side2 = 0; side3 = 0; } public QudratullahMommandi_Triangle_06(double sideOne, double sideTwo, double sideThree) { side1 = sideOne; side2 = sideTwo; side3 = sideThree; } public void giveLength(double firstSide, double secondSide, double thirdSide) { while (firstSide <= 0 ){ System.out.println("The first side must be greater then zero " + "please enter a new value"); firstSide = keyboard.nextDouble(); } while (secondSide <=0){ System.out.println("The second side must be greater then zero " + "please enter a new value"); secondSide = keyboard.nextDouble(); } while (thirdSide <=0){ System.out.println("The third side must be greater then zero " + "please enter a new value"); thirdSide = keyboard.nextDouble(); } side1 = firstSide; side2 = secondSide; side3 = thirdSide; }// end giveLength public void outPut() { System.out.println("The first side is " + side1 +"\n" + "The second side is " + side2 + "\n" + "The third side is " + side3); }// end outPut public double getPerim() { double perimeter = side1 + side2 + side3; return perimeter; }// end getPerim public double getArea() { double semiP = (side1+side2+side3)/2; double area = Math.sqrt(semiP*(semiP-side1)*(semiP-side2)*(semiP-side3)); return area; }// end getArea
Here's the code for my other class in which I use the triangle class
import java.util.Scanner; public class QudratullahMommandi_S_06 { public static void main (String[]args) { QudratullahMommandi_Triangle_06 triangle1 = new QudratullahMommandi_Triangle_06(); double perimeter; double area; Hello(); triangle1.giveLength(4,5,6); perimeter = triangle1.getPerim(); area = triangle1.getArea(); Output(); }// end main public static void Hello() { System.out.println("This program uses the triangle class and its methods\n" + "to calculate the perimeter and area of a triangle given three side lengths"); System.out.println("--------------------------------------"); System.out.println("Qudratullah Mommandi"); } public static String Output() { triangle1.outPut(); } }// end class
and here's the error message
QudratullahMommandi_S_06.java:46: error: cannot find symbol
{ triangle1.outPut();
^
symbol: variable triangle1
location: class QudratullahMommandi_S_06
1 error