组装一台电脑
計(jì)算機(jī)硬件接口類:
/*** @author Administrator* CPU接口*/ public interface CPU {public String getBand();public String getZhuPin(); }/*** @author Administrator* 內(nèi)存接口*/ public interface Dimm {public String dimmSize(); }/*** @author Administrator* 硬盤接口*/ public interface SD {public String sdSize(); }硬件生產(chǎn)商類:
/*** @author Administrator* CPU生產(chǎn)商*/ public class CPUpro implements CPU{public String getBand() {return "Intel"; }public String getZhuPin() {return "3.8GHz"; }}/*** @author Administrator* 內(nèi)存生產(chǎn)商*/ public class DimmPro implements Dimm{@Overridepublic String dimmSize() {// TODO Auto-generated method stubreturn "4GB";}}/*** @author Administrator* 硬盤生產(chǎn)商*/ public class SDpro implements SD{@Overridepublic String sdSize() {return "3000GB";} }計(jì)算機(jī)類:
/*** @author Administrator* 計(jì)算機(jī)類*/ public class Computer {private CPU cpu;private SD sd;private Dimm dimm;public Computer() {}public Computer(CPU cpu, SD sd, Dimm dimm) {super();this.cpu = cpu;this.sd = sd;this.dimm = dimm;}public void print() {System.out.println("計(jì)算機(jī)的信息如下:");System.out.println("CPU的品牌是:"+cpu.getBand()+",主頻是:"+cpu.getZhuPin());System.out.println("硬盤容量是:"+sd.sdSize());System.out.println("內(nèi)存容量是:"+dimm.dimmSize());}public CPU getCpu() {return cpu;}public void setCpu(CPU cpu) {this.cpu = cpu;}public SD getSd() {return sd;}public void setSd(SD sd) {this.sd = sd;}public Dimm getDimm() {return dimm;}public void setDimm(Dimm dimm) {this.dimm = dimm;}}測(cè)試類:
public class Text {public static void main(String[] args) {CPU cpu = new CPUpro();SD sd = new SDpro();Dimm dimm = new DimmPro();Computer computer = new Computer(cpu,sd,dimm);computer.print();} }運(yùn)行結(jié)果:
?
轉(zhuǎn)載于:https://www.cnblogs.com/Dean-0/p/11208720.html
總結(jié)
- 上一篇: Docker镜像加速,设置国内源
- 下一篇: 企业官网示例以及数据库表结构