class HD {
private int volume;
public HD(int volume) {
this.volume = volume;
}
public int getVolume() { return this.volume;}
}
class CPU {
private String model;
public CPU(String model) {
this.model = model;
}
public String getModel() { return this.model;}
}
class Computer {
private HD[] hdList;
}
private CPU[] cpuList;
public Computer(HD[] hd,CPU[] cpu) {
this.hdList = hd;
this.cpuList = cpu;
}
public String getComputer() {
return "CPU个数:" + this.cpuList.length
+"硬盘个数:"+this.hdList.length;
}
public void show() {
for(HD hd:this.hdList)
System.out.println("硬盘容量:"+ hd.getVolume());
for(CPU cpu:this.cpuList)
System.out.println("CPU型号:"+cpu.getModel());
}
}
public class hsuzu {
public static void main(String[] args) {
HD[] hd = new HD[] {new HD(1000),new HD(500)};
CPU[] cpu = new CPU[] {new CPU("华为麒麟 处理器1")},
new CPU("华为麒麟 处理器2")};
Computer mate = new Computer(hd,cpu);
System.out.println(mate.getCoumputer());
mate.show();
}
}
Java学习打卡day17
最新推荐文章于 2024-06-04 23:11:16 发布