半径为r,圆环半径为3m,已知最外边砌8元/米的围墙,圆环做过道10元/平方米,求造价。
package day141020;
/**
* 圆类
* @author XWJ
*
*/
public class Circle {
private double radius; // 半径
/**
* 构造器
* @param radius 圆的半径
*/
public Circle(double radius) {
this.radius = radius;
}
/**
* 计算面积
* @return
*/
public double getArea() {
return Math.PI * radius * radius;
}
/**
* 计算周长
* @return
*/
public double getCircumference() {
return 2 * Math.PI * radius;
}
}
package day141020;
import java.util.Scanner;
public class CircleRun {
private static final double FP = 8.5;
private static final double CP = 12;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入游泳池的半径: ");
if(sc.hasNextDouble()) {
double r = sc.nextDouble();
Circle small = new Circle(r);
Circle big = new Circle(r + 3);
System.out.printf("围墙的造价为: ¥%.1f元\n", FP * big.getCircumference());
System.out.printf("过道的造价为: ¥%.1f元\n", CP * (big.getArea() - small.getArea()));
}
else {
System.out.println("输入错误!!!");
}
sc.close();
}
}