java 设计一个geometricobject类,geometricobject类
时间: 2024-01-20 20:04:11 浏览: 68
GeometricObject.java
可以作为所有几何对象的父类,包含一些基本属性和方法。这个类可以包含以下属性和方法:
属性:
- color:表示几何对象的颜色
- filled:表示几何对象是否被填充
- dateCreated:表示对象创建的日期
方法:
- getColor():获取几何对象的颜色
- setColor():设置几何对象的颜色
- isFilled():检查几何对象是否被填充
- setFilled():设置几何对象是否被填充
- getDateCreated():获取几何对象的创建日期
- toString():返回几何对象的字符串表示
代码实现如下:
```java
public class GeometricObject {
private String color;
private boolean filled;
private Date dateCreated;
public GeometricObject() {
dateCreated = new Date();
}
public GeometricObject(String color, boolean filled) {
dateCreated = new Date();
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public Date getDateCreated() {
return dateCreated;
}
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color + " and filled: " + filled;
}
}
```
阅读全文