定义一个 Room 类,包含成员变量面积和高度,以及内部类 Table 和 Chair , Table 和 Chair 皆包含成员变量长、宽、高以及颜色。现将一张长宽高分别为100cm,100cm,80cm的白色桌子以及一把长宽高分别为40cm,30cm,50cm的黑色椅子放进个面积为60平米,高度为4米的房间。编程打印房间、桌子、椅子的信息。
public class Room {
static Double mianji=60d;
static Double gaodu=4D;
public static void main(String[] args) {
Table table=new Table();
Chair chair=new Chair();
System.out.println(mianji);
System.out.println(gaodu);
System.out.println(table);
System.out.println(chair);
}
private static class Table {
String color="白色";
Double height=100D;
Double weight=100D;
Double length=80D;
@Override
public String toString() {
return "Table{" +
"color='" + color + '\'' +
", height=" + height +
", weight=" + weight +
", length=" + length +
'}';
}
}
private static class Chair {
String color="黑色";
Double height=50D;
Double weight=30d;
Double length=40D;
@Override
public String toString() {
return "Chair{" +
"color='" + color + '\'' +
", height=" + height +
", weight=" + weight +
", length=" + length +
'}';
}
}
}