mardi 24 février 2015

How do I call the first area method from the main method?



I need the area method that contains the formula for the area of a circle to take in the radius that was found by the other area method that calculated the distance...So one of the area methods calculated the distance/radius then I want that answer to be used in the the radius of the area method for the area of a circle.



public static void main(String[] args) {

Scanner reader = new Scanner (System.in);

double x1, x2, y1, y2;

System.out.println("x1: ");
x1 = reader.nextInt();
System.out.println("x2: ");
x2 = reader.nextInt();
System.out.println("y1: ");
y1 = reader.nextInt();
System.out.println("y2: ");
y2 = reader.nextInt();

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

System.out.println(distance);

double radius = area();

System.out.println(radius);


}

public static double area (double radius) {
double areaCircle;
double powRadius;
double radius = 1; //PLACEHOLDER


powRadius = Math.pow(radius, 2);
areaCircle = (Math.PI *(powRadius));
return areaCircle;


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



Aucun commentaire:

Enregistrer un commentaire