package PersonalComputer;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CPU cpu =new CPU();
HardDisk disk =new HardDisk();
PC pc = new PC();
cpu.setSpeed(2200);
disk.setAmount(200);
pc.setCPU(cpu);
pc.setHardDisk(disk);
pc.show();
}
}
class CPU{
private int speed;
public void setSpeed(int speed){
this.speed=speed;
}
public int getSpeed(){
return speed;
}
}
class HardDisk{
private int amount;
public void setAmount(int amount){
this.amount=amount;
}
public int getAmount(){
return amount;
}
}
class PC{
private CPU cpu;
private HardDisk HD;
public void setCPU(CPU cpu){
this.cpu=cpu;
}
public void setHardDisk(HardDisk HD){
this.HD=HD;
}
public void show(){
System.out.println("CPU速度:"+cpu.getSpeed());
System.out.println("硬盘容量是:"+HD.getAmount());
}
}
课堂练习5
最新推荐文章于 2022-12-01 00:04:31 发布