1) 编写图形类 Geom,有私有的属性:颜色和是否填充,定义公共的构造方法、获取各
个属性的方法和获取图形信息的方法:
(2)编写继承图形类的矩形类 Rectangle,有私有的属性:长和宽,定义公共的构造方法、
获取各个属性的方法和求面积的方法:
(3)编写继承矩形类的长方体类Rectlinder,有私有属性:高,定义公共的构造方法、获
取属性的方法和求体积的方法,重写图形信息的方法。
(4 设计一个入口主类,构造若干的立方体,把他们的数据和行为列举出来
根据类图定义出类,然后创建对象,调用类的成员方法。具体类的设计如下:
这不就是将文字翻译成代码? 按照要求来 就好了啊
/**
* 1) 编写图形类 Geom,有私有的属性:颜色和是否填充,定义公共的构造方法、获取各
* 个属性的方法和获取图形信息的方法:
*/
public class Geom {
private String color;
private String filling;
public Geom(String color, String filling) {
this.color = color;
this.filling = filling;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getFilling() {
return filling;
}
public void setFilling(String filling) {
this.filling = filling;
}
@Override
public String toString() {
return "Geom{" +
"color='" + color + '\'' +
", filling='" + filling + '\'' +
'}';
}
}
package entity;
/**
* (3)编写继承矩形类的长方体类Rectlinder,有私有属性:高,定义公共的构造方法、获
* 取属性的方法和求体积的方法,重写图形信息的方法。
*/
public class Rectlinder extends Rectangle{
private Double height;
public Rectlinder(Double length, Double width, Double height) {
super(length, width);
this.height = height;
}
public Double getHeight() {
return height;
}
public void setHeight(Double height) {
this.height = height;
}
public Double getVolume(Double length, Double width, Double height){
return length * width * height;
}
@Override
public String toString() {
return "Rectlinder{" +
"length=" + super.getLength() +
"width=" + super.getWidth() +
"height=" + height +
'}';
}
}
package entity;
/**
* (2)编写继承图形类的矩形类 Rectangle,有私有的属性:长和宽,定义公共的构造方法、
* 获取各个属性的方法和求面积的方法:
*/
public class Rectangle {
private Double length;
private Double width;
public Rectangle(Double length, Double width) {
this.length = length;
this.width = width;
}
public Double getLength() {
return length;
}
public void setLength(Double length) {
this.length = length;
}
public Double getWidth() {
return width;
}
public void setWidth(Double width) {
this.width = width;
}
public Double getArea(Double length, Double width){
return length * width;
}
}