Here's an assignment I have to do for school:
I'm not sure if my code is right but obviously there is something wrong because it isn't working...
public static void main(String[] args) {
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();
}
public static void area(double radius, int x1, int x2, int y1, int y2)
{
double areaCircle = (Math.PI * area(x1, x2, y1, y2) * area(x1, x2, y1, y2));
}
public static double area(int x1, int x2, int y1, int y2) {
double radius = distance (x1, y1, x2, y2);
return radius;
}
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;
}
//NewLine Method
public static void newLine () {
System.out.println ("");
}
As previously mentioned, your code never calls any of the calculation methods, meaning that they're never run and area etc. is never calculated. There isn't any code for displaying the result either.
In addition, the area method doesn't even return anything, meaning that it calculates the value and then discards it.
Your main
didn't call any of the other methods!. Complete the code first.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.