Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Need Help On Method



I have a code:

import java.util.*;

public class CalculateSteps
{
    // This method is the main method
   public static void main(String[] args)
    {
       int userOption=0;
        // Begin Scanner
       Scanner input = new Scanner(System.in);
        // Insert Constant
       final double PI = 3.14159;
    
        // Begin off the choices from the menu
          do{
      System.out.println("Pick one of the following as a number:");
      System.out.println("1. Triangle");
      System.out.println("2. Circle");
      System.out.println("3. Exit");
     
              // If the user choices to exit, terminate program
      userOption = input.nextInt();
             if (userOption == 3)
                 {
                    System.out.println("See you.");
                    System.exit(0);
                       }
                  }
                  // If the user doesnt choose 1 or 2 bring up the choices again
        while(userOption!=1 && userOption!=2);
        {
            return userOption;
           }
         
           // If the user choices 1; triangle.
      if(userOption == 1)
  {
     // Enter the coordinates of the points
      System.out.print("Coordinate of x point 1:");
      double x1 = input.nextDouble();
      System.out.print("Coordinate of y point 1:");
      double y1 = input.nextDouble();
      System.out.print("Coordinate of x point 2:");
      double x2 = input.nextDouble(); 
      System.out.print("Coordinate of y point 2:");
      double y2 = input.nextDouble();
      System.out.print("Coordinate of x point 3:");
      double x3 = input.nextDouble(); 
      System.out.print("Coordinate of y point 3:");
      double y3 = input.nextDouble();
     
      // pass it onto method below
      perimeterTri(x1,x2,x3,y1,y2,y3);
     
  }
// if the user chooses option 2
     if(userOption == 2)
{
    //Prompt user to enter radius of Circle
     System.out.print("Please enter the radus of the circle:");
    double radius = input.nextDouble();
   
    // Pass onto method of circle below
    perimeterCircle(r);
}
          
   // Method of Triangle
  
   public static void perimeterTri( double x1 , double x2 , double x3 , double y1 , double y2 , double y3 )
       {
       // declate the variables for distance and perimeter
       double distance1, distance2, distance3, perimeter;
      
      // use the distance formula to find the distance
      distance1 = Math.sqrt(Math.pow(x2 - x1,2) + Math.pow(y2 - y1,2));
      distance2 = Math.sqrt(Math.pow(x3 - x1,2) + Math.pow(y3 - y1,2));
      distance3 = Math.sqrt(Math.pow(x3 - x2,2) + Math.pow(y3 - y2,2)); 
      
       // find the perimeter by adding the distances
      perimeter = distance1 + distance2 + distance3;
     
      System.out.println("The perimter for the triangle at the following points is" + perimeter);
   
}
// Method of circle

   public static void perimeterCircle(double r)
       {
           // Formula for perimeter
       double perimeter = 2 * PI * r;
           // Print out the perimeter
       System.out.println("The perimeter of the circle with radius" +radius+ "is:" +perimeter);
       }
;
       }
     
   } 

My only problem is im recieving an Illegal Expression on this:

public static void perimeterTri( double x1 , double x2 , double x3 , double y1 , double y2 , double y3 )

And I have no idea why.

Anyone can help?