Results 1 to 4 of 4
  1. #1
    tinker99 is offline Member
    Join Date
    Sep 2014
    Posts
    11
    Rep Power
    0

    Default 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; //Semi-Perimeter
           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) * (s-a) * (s-b) * (s-c));
           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
    My errors are:

    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) * (s-a) * (s-b) * (s-c));
    ^
    symbol: variable x
    location: class ShelbyHarms_3_02
    ShelbyHarms_3_02.java:39: error: cannot find symbol
    x = ((s) * (s-a) * (s-b) * (s-c));
    ^
    symbol: variable s
    location: class ShelbyHarms_3_02
    ShelbyHarms_3_02.java:39: error: illegal start of type
    x = ((s) * (s-a) * (s-b) * (s-c));
    ^
    ShelbyHarms_3_02.java:39: error: cannot find symbol
    x = ((s) * (s-a) * (s-b) * (s-c));
    ^
    symbol: variable s
    location: class ShelbyHarms_3_02
    ShelbyHarms_3_02.java:39: error: cannot find symbol
    x = ((s) * (s-a) * (s-b) * (s-c));
    ^
    symbol: variable s
    location: class ShelbyHarms_3_02
    ShelbyHarms_3_02.java:39: error: cannot find symbol
    x = ((s) * (s-a) * (s-b) * (s-c));
    ^
    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

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    10

    Default 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.

  3. #3
    tinker99 is offline Member
    Join Date
    Sep 2014
    Posts
    11
    Rep Power
    0

    Default Re: help with java assignments for class?

    Quote Originally Posted by Ronin View Post
    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.
    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; //Semi-Perimeter
           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) * (s-a) * (s-b) * (s-c));
           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:

  4. #4
    tinker99 is offline Member
    Join Date
    Sep 2014
    Posts
    11
    Rep Power
    0

    Default Re: help with java assignments for class?

    Nvm. I figured it out. Still new this and make a lot of stupid java mistakes

Similar Threads

  1. JAVA Assignments.
    By hawk-dc in forum New To Java
    Replies: 1
    Last Post: 03-17-2014, 10:17 PM
  2. Java Exercises --- Assignments
    By Martyn in forum Forum Lobby
    Replies: 4
    Last Post: 11-22-2012, 07:07 PM
  3. Java Array Assignments?
    By abimaran in forum New To Java
    Replies: 9
    Last Post: 11-04-2009, 07:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •