码迷,mamicode.com
首页 > 编程语言 > 详细

用类描述计算机中CPU的速度和硬盘的容量。(Java)

时间:2018-10-15 20:37:51      阅读:834      评论:0      收藏:0      [点我收藏+]

标签:ati   rdd   image   highlight   static   速度   计算机   com   etc   

PC.java

public class PC {
	CPU cpu;
	HardDisk HD;
	public void setCPU(CPU c) {
		this.cpu = c;
	}
	
	public void setHardDisk(HardDisk h) {
		HD = h;
	}
	
	public void show() {
		System.out.println("cpu: " +cpu.getSeepd());
		System.out.println("Hd: "+HD.getAmount());
	}

	
}

  CPU.java

public class CPU {
	private int speed;
	
	public void setSeepd(int m) {
		this.speed = m;
	}
	public int getSeepd() {
		return speed;
	}
}

  HardDisk.java

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

  Test.java

public class Test {
	public static void main(String[] args) {
		CPU cpu =new CPU();
		cpu.setSeepd(2000);
		
		HardDisk disk = new HardDisk();
		disk.setAmount(200);
		
		PC pc =new PC();
		pc.setCPU(cpu);
		pc.setHardDisk(disk);
		pc.show();
	}
}

  运行结果:

技术分享图片

用类描述计算机中CPU的速度和硬盘的容量。(Java)

标签:ati   rdd   image   highlight   static   速度   计算机   com   etc   

原文地址:https://www.cnblogs.com/wuyibb/p/9792707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!