用类描述电脑CPU的速度和硬盘的容量

来源:互联网 发布:电脑微信群发软件 编辑:程序博客网 时间:2024/03/29 20:29
package five;


public class CPU {
int spend;

void setSpend(int m){
this.spend = m;
}

int getSpend(){
return spend;
}


}

package five;


public class HardDisk {
int amount;

void setAmount(int m){
this.amount = m;
}
int getAmount(){
return amount;
}


}

package five;


public class PC {
CPU cpu;
HardDisk HD;

void setCPU(CPU c){
this.cpu = c;
}

void setHardDisk(HardDisk h){
this.HD = h;
}

void show(){
System.out.println("cpu速度为:"+cpu.spend+"硬盘容量为:"+HD.amount);
}

}

package five;


public class Test {


public static void main(String[] args) {
CPU cpu = new CPU();
cpu.setSpend(2000);

HardDisk disk = new HardDisk();
disk.setAmount(200);

PC pc = new PC();
pc.setCPU(cpu);
pc.setHardDisk(disk);
pc.show();
}


}


阅读全文
0 0
原创粉丝点击