public class Circle {
private String color;
private int radius;
public Circle() {
}
// 顯示顏色
public String showColor() {
return color;
}
// 設置顏色
public void setColor(String color) {
this.color = color;
}
// 顯示半徑
public int showRadius() {
return radius;
}
// 設置半徑
public void setRadius(int radius) {
this.radius = radius;
}
// 計算周長
public double getGirth() {
return 2 * Math.PI * this.showRadius();
}
// 計算面積
public double getArea() {
return Math.PI * this.getGirth() * this.showRadius();
}
public static void main(String[] args) {
Circle circle = new Circle();
Scanner sc = new Scanner(System.in);
int count = 1;
int rad = 0;
String cor = null;
while(true){
if(count%2==1){
System.out.println("請輸入半徑:");
rad = sc.nextInt();
}else{
System.out.println("請輸入顏色:");
cor = sc.next();
circle.setRadius(rad);//設置半徑
circle.setColor(cor);//設置顏色
System.out.println("圓的半徑為:" + circle.showRadius() + " 顏色是:"
+ circle.showColor() + " 周長為:" + circle.getGirth() + " 面積為:"
+ circle.getArea());
}
count++;
}
}
}