编译我的 main 时出现错误,并且错误来自我的类文件。这样做的目的是创建一个程序,该程序要求用户创建一个圆,然后将面积、直径和周长返回给用户。
java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double circumference;
double radius = 5.7;
double pi = 3.14159;
double area = 0;
Circle circleobject = new Circle();
//Get radius
System.out.println("What is the circle's Radius?");
radius = keyboard.nextDouble();
if (radius == 0.0) {
radius = 5.7;
}
System.out.println("Creating a circle object.");
//Creating the class object
Circle circle = new Circle();
System.out.println("Your circle's area: " + Circle.getArea());
System.out.println("Your circle's Diameter " + Circle.getDiameter());
System.out.println("Your circle's Circumference " + Circle.getCircumference());
}
这是我的类文件
public class Circle {
double circumference;
double radius = 0.0;
double pi = 3.14159;
double area = 0;
public void setRadius() {
radius = radius;
}
public void radius() {
radius = 0.0;
}
public void getArea(double area) {
area = 0;
area = pi * radius * radius;
}
public void getDiameter(double diameter) {
diameter = radius * 2;
}
public void getCircumference(double circumference) {
circumference = 2 * pi * radius;
}
}
这是我编译主程序时出现的错误。
Driver.java:38: error: method getCircumference in class Circle cannot be applied to given types;
System.out.println("Your circle's Circumference " + Circle.getCircumference());
^
required: double
found: no arguments
reason: actual and formal argument lists differ in length
1 error