Results 1 to 4 of 4
 09282014, 09:10 PM #1Member
 Join Date
 Sep 2014
 Posts
 11
 Rep Power
 0
help with java assignments for class?
I am having trouble figuring out why java is giving me an error for the symbols. I will post the errors below the code.
Java Code:import java.util.Scanner; public class ShelbyHarms_3_02 { public static void main(String[] args) { Scanner console = new Scanner(System.in); double s = 0; //SemiPerimeter double x = 0; // Perimeter of triangle double area = 0; //Area of triangle double a, b, c = 0; //Input sides of triangle //Input lengths of triangle System.out.print("Please enter triangle side a: "); a = console.nextDouble(); System.out.print("Please enter triangle side b: "); b = console.nextDouble(); System.out.print("Please enter triangle side c: "); c = console.nextDouble(); } //Calculations for area and perimeter public static double triangleArea (double a, double b, double c) { s = (a + b + c)/2.0; x = ((s) * (sa) * (sb) * (sc)); area = Math.sqrt(x); return area; //Output the results System.out.println("Your three triangle lengths are: " + '\n' + a + '\n' + b + '\n' + c); System.out.println("The area of your triangle is: " + triangleArea(a, b, c)); } // End main() } // End class
ShelbyHarms_3_02.java:38: error: cannot find symbol
s = (a + b + c)/2.0;
^
symbol: variable s
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:39: error: cannot find symbol
x = ((s) * (sa) * (sb) * (sc));
^
symbol: variable x
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:39: error: cannot find symbol
x = ((s) * (sa) * (sb) * (sc));
^
symbol: variable s
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:39: error: illegal start of type
x = ((s) * (sa) * (sb) * (sc));
^
ShelbyHarms_3_02.java:39: error: cannot find symbol
x = ((s) * (sa) * (sb) * (sc));
^
symbol: variable s
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:39: error: cannot find symbol
x = ((s) * (sa) * (sb) * (sc));
^
symbol: variable s
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:39: error: cannot find symbol
x = ((s) * (sa) * (sb) * (sc));
^
symbol: variable s
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:40: error: cannot find symbol
area = Math.sqrt(x);
^
symbol: variable area
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:40: error: cannot find symbol
area = Math.sqrt(x);
^
symbol: variable x
location: class ShelbyHarms_3_02
ShelbyHarms_3_02.java:42: error: cannot find symbol
return area;
^
symbol: variable area
location: class ShelbyHarms_3_02
10 errors
 09282014, 10:05 PM #2Senior Member
 Join Date
 Oct 2010
 Posts
 393
 Rep Power
 10
Re: help with java assignments for class?
Hi tinker99, welcome.
All of the variables used have been defined as local variables within the main method so are not know by the triangleArea method. Simply move the declaration of the required variables to within the triangleArea method.
Regards.
 09282014, 10:48 PM #3Member
 Join Date
 Sep 2014
 Posts
 11
 Rep Power
 0
Re: help with java assignments for class?
Thank you. It now runs except now its not calculating area
Java Code:import java.util.Scanner; public class ShelbyHarms_3_02 { public static void main(String[] args) { Scanner console = new Scanner(System.in); double s = 0; //SemiPerimeter double x = 0; // Perimeter of triangle double area = 0; //Area of triangle double a, b, c = 0; //Input sides of triangle //Input lengths of triangle System.out.print("Please enter triangle side a: "); a = console.nextDouble(); System.out.print("Please enter triangle side b: "); b = console.nextDouble(); System.out.print("Please enter triangle side c: "); c = console.nextDouble(); //Calculations for area and perimeter s = (a + b + c)/2.0; x = ((s) * (sa) * (sb) * (sc)); area = Math.sqrt(x); //Output the results System.out.println("Your three triangle lengths are: " + '\n' + a + '\n' + b + '\n' + c); System.out.println("The area of your triangle is: "); } // End main() } // End class
Please enter triangle side a: 4
Please enter triangle side b: 8
Please enter triangle side c: 12
Your three triangle lengths are:
4.0
8.0
12.0
The area of your triangle is:
 09282014, 11:27 PM #4Member
 Join Date
 Sep 2014
 Posts
 11
 Rep Power
 0
Similar Threads

JAVA Assignments.
By hawkdc in forum New To JavaReplies: 1Last Post: 03172014, 09:17 PM 
Java Exercises  Assignments
By Martyn in forum Forum LobbyReplies: 4Last Post: 11222012, 06:07 PM 
Java Array Assignments?
By abimaran in forum New To JavaReplies: 9Last Post: 11042009, 06:18 PM
Bookmarks