import java.util.Scanner;
public class Yuanzhui {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
double r=scanner.nextDouble();
double h=scanner.nextDouble();
Circle c = new Circle();
c.setRadius(r);
Cone cone=new Cone();
cone.setBottom(c);
cone.setHeight(h);
System.out.printf("底面面积和周长分别为:%.2f %.2f\n",cone.getBottom().getArea(),cone.getBottom().getLength());
System.out.printf("体积为:%.2f\n",cone.getVolume());
scanner.close();
}
}
class Circle{
private double radius;
public void setRadius(double radius) {
this.radius=radius;
}
public double getRadius() {
return this.radius;
}
public double getArea() {
return this.radius*this.radius*Math.PI;
}
public double getLength() {
return 2*this.radius*Math.PI;
}
}
class Cone extends Circle{
private double height;
private double bottom;
public Cone() {
this.bottom=super.getArea();
}
public void setBottom(Circle circle) {
this.bottom=circle.getArea();
super.getLength();
super.getArea();
}
public double getBottom() {
return this.bottom;
}
public double getHeight() {
return this.height;
}
public void setHeight(double height) {
this.height=height;
}
public double getVolume() {
return this.height*this.bottom/3.0;
}
}
以上代码存在编译问题:
Exception in thread "main" java,lang.Error: Unresolved compilation problems:
Cannot invoke getArea() on the primitive type double
Cannot invoke getLength() on the primitive type double
The method printf(String, Object[]) in the type PrintStream is not applicable for the
arguments (String, double)
希望知道该如何解决,谢谢。