java test circle_TestCircle.java
import java.util.Scanner;
public class TestCircle {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
/*Circle c1 = new Circle();
System.out.print("第一個圓已經生成, 它的半徑是:");
System.out.println(c1.getRadius() + "cm");
System.out.print("它的面積是:");
System.out.printf("%.2f平方厘米\n", c1.getArea());
System.out.print("它的顏色是默認的");
System.out.println(c1.getColor());
System.out.print("\n輸入第二個圓的半徑和顏色: ");
Circle c2 = new Circle(sc.nextDouble(), sc.nextLine());
System.out.print("第二個圓已經生成, 它的半徑是:");
System.out.println(c2.getRadius() + "cm");
System.out.print("它的面積是:");
System.out.printf("%.2f平方厘米\n", c2.getArea());
System.out.print("它的顏色是");
System.out.println(c2.getColor());
System.out.print("\n修改第二個圓的顏色為: ");
c2.setColor(sc.nextLine());
System.out.print("修改后它的顏色是");
System.out.println(c2.getColor());
*/
System.out.print("\n輸入第三個圓的半徑: ");
Circle c3 = new Circle(sc.nextDouble());
System.out.println(c3.toString());
sc.close();
}
}
class Circle {
private double radius;
private String color;
public Circle() {
radius = 1;
color = "紅色";
}
public Circle(double radius) {
this.radius = radius;
this.color = "白色";
}
public Circle(double radius, String color) {
this.radius = radius;
this.color = color;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String toString(){
StringBuffer sb = new StringBuffer();
sb.append("Circle: [ radius=");
sb.append(this.radius);
sb.append(", color=");
sb.append(this.color);
sb.append(" ]");
return sb.toString();
}
public double getArea() {
return Math.PI * this.radius * this.radius;
}
}
一鍵復制
編輯
Web IDE
原始數據
按行查看
歷史
總結
以上是生活随笔為你收集整理的java test circle_TestCircle.java的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 的好处_女性做下蹲运动有什么好处 原来有
- 下一篇: aop的实现原理_非Spring管理Be