cpu速度和硬盘容量

public class CPU {
	int speed;
	public int getSpeed()
	{
		int sp;
		sp=this.speed;
		return sp;
	}
	
	public void setSpeed(int m)
	{
		this.speed=m;
	}
}

public class HardDisk {
	int amount;
	public int getAmount()
	{
		int am;
		am=this.amount;
		return am;
	}
	
	public void setAmount(int m)
	{
		this.amount=m;
	}
}

public class PC {
	CPU cpu = new CPU();
	HardDisk HD = new HardDisk();
	public void setCPU(CPU c)
	{
		this.cpu=c;
	}
	
	public void setHardDisk(HardDisk h)
	{
		this.HD=h;
	}
	
	public void show()
	{
		System.out.println("CPU速度:"+cpu.getSpeed());
		System.out.println("硬盘容量:"+HD.getAmount());
	}
}

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//
		CPU cpu = new CPU();
		cpu.setSpeed(2200);
		
		HardDisk disk = new HardDisk();
		disk.setAmount(200);
		
		PC pc = new PC();
		pc.setCPU(cpu);
		pc.setHardDisk(disk);
		pc.show();
	}

}


运行结果:

cpu速度和硬盘容量_第1张图片

你可能感兴趣的:(Java小项目)