当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1550:例:程序清单11-8

题目描述

书写课本代码;实现课本上的样例输出;

给出需要的类;

public class Circle4 extends GeometricObject1 {
  private double radius;

  public Circle4() {
  }

  public Circle4(double radius) {
    super();
    this.radius = radius;
  }

  public Circle4(double radius, String color, boolean filled) {
    super(color, filled);
    this.radius = radius;
    //setColor(color);
    //setFilled(filled);
  }

  /** Return radius */
  public double getRadius() {
    return radius;
  }

  /** Set a new radius */
  public void setRadius(double radius) {
    this.radius = radius;
  }

  /** Return area */
  public double getArea() {
    return radius * radius * Math.PI;
  }
 
  /** Return diameter */
  public double getDiameter() {
    return 2 * radius;
  }
 
  /** Return perimeter */
  public double getPerimeter() {
    return 2 * radius * Math.PI;
  }

  /* Print the circle info */
  public void printCircle() {
    System.out.println(toString() + "The circle is created " + getDateCreated() +
      " and the radius is " + radius);
  }
 
  public String toString() {
    return "Circle WWWW " + getColor() + super.toString();
  }
}
public class GeometricObject1 {
  private String color = "white";
  private boolean filled;
  private java.util.Date dateCreated;
 
  /** Construct a default geometric object */
  public GeometricObject1() {
    dateCreated = new java.util.Date();
  }

  /** Construct a geometric object with the specified color
    *  and filled value */
  public GeometricObject1(String Color, boolean filled) {
    dateCreated = new java.util.Date();
    this.color = color;
    this.filled = filled;
  }

  /** Return color */
  public String getColor() {
    return color;
  }

  /** Set a new color */
  public void setColor(String color) {
    this.color = color;
  }

  /** Return filled. Since filled is boolean,
     its get method is named isFilled */
  public boolean isFilled() {
    return filled;
  }

  /** Set a new filled */
  public void setFilled(boolean filled) {
    this.filled = filled;
  }
 
  /** Get dateCreated */
  public java.util.Date getDateCreated() {
    return dateCreated;
  }
 
  /** Return a string representation of this object */
  public String toString() {
    return "created on " + dateCreated + "\ncolor: " + color +
      " and filled: " + filled;
  }
}


输入解释
无输入
输出解释
见课表清单11-8
提示
数组线性表ArrayList类的练习。

该题目包含在题集 SSPU

题目来源 sspu

共提交 16

通过率 6.25%
时间上限 内存上限
1000 MS 128 MB