0

i keep getting an error message on this one piece of code. i tried declaring it and passing it in a tone of different ways. my apologies if the code isn't that advanced. i'm still a beginner.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication5;
import java.util.Scanner;

/**
 *
 * @author period3
 */
public class JavaApplication5 {

/**
 * @param args the command line arguments
 */


public static void main(String[] args) {


    double theresult;
    theresult = area(double radius);

Scanner reader;
reader = new Scanner (System.in);
System.out.println("Please enter the coordinates of a circle:");
newLine();
System.out.println("Outside point:");
newLine();
System.out.println("x1:");
int x1 = reader.nextInt();
newLine();
System.out.println("y1:");
int y1 = reader.nextInt();
newLine();
System.out.println("Center Point:");
newLine();
System.out.println("x2:");
int x2 = reader.nextInt();
newLine();
System.out.println("y2:");
int y2 = reader.nextInt();

System.out.println("The area of the circle is" + theresult);

}
 public static double distance(int x1, int y1, int x2, int y2) 
{
double dx = x2 - x1;
double dy = y2 - y1;
double dsquared = dx*dx + dy*dy;
double result = Math.sqrt (dsquared);
return result;
}

public static double area(int x1, int y1, int x2, int y2) {
double radius = distance (x1, y1, x2, y2);
return radius;
}

public static double area(double radius)
{
    double areaCircle;
    areaCircle = (3.14 * (radius * radius));
    return areaCircle;
}


//NewLine Method
public static void newLine () {
System.out.println ("");
}
}

and my error message on line 24 (theresult = area(double radius):

unexpected type
  required: value
  found:    class

'.class' expected

';' expected
----

1 Answers1

0

You need to calculate the radius first before using the area method:

double radius = distance(x1, y1, x2, y2);

Then you need to set the result:

theResult = area(radius);

These should both happen after your user input (after they have given you values for x1, y1, x2, and y2, and before you print theResult.

Notice how I call your distance and area methods. Simply by inputting the local variables to the parameters.

theResult = area(double radius); <- This is incorrect syntax.
NominSim
  • 8,447
  • 3
  • 28
  • 38