package com.day10; public interface Cpu { public String Pingpai(); public String ZhuPin(); }
package com.day10; public class CpuType implements Cpu { public String Pingpai(){ return "Inter"; } public String ZhuPin(){ return "3.8"; } }
package com.day10; public interface Ems { public String Capacity(); }
package com.day10; public class EmsType implements Ems { public String Capacity(){ return "16G"; } }
package com.day10; public interface HardDisk { public String Size(); }
package com.day10; public class HardDiskType implements HardDisk { public String Size(){ return "500G"; } }
package com.day10; public class Computer { public Cpu getCpu() { return cpu; } public void setCpu(Cpu cpu) { this.cpu = cpu; } public Ems getEms() { return ems; } public void setEms(Ems ems) { this.ems = ems; } public HardDisk getHardDisk() { return hardDisk; } public void setHardDisk(HardDisk hardDisk) { this.hardDisk = hardDisk; } private Cpu cpu; private Ems ems; private HardDisk hardDisk; public Computer(){} public Computer(Cpu cpu,Ems ems,HardDisk hardDisk){ super(); this.cpu = cpu; this.ems = ems; this.hardDisk = hardDisk; } public void print(){ System.out.println("计算机的信息:"); System.out.println("cpu品牌是"+cpu.Pingpai()+",主频是"+cpu.ZhuPin()); System.out.println("内存的容量是"+ems.Capacity()); System.out.println("硬盘容量是"+hardDisk.Size()); } }
package com.day10; public class Test { public static void main(String[] args) { Cpu cpu = new CpuType(); Ems ems = new EmsType(); HardDisk hardDisk = new HardDiskType(); Computer computer = new Computer(cpu,ems,hardDisk); computer.print(); } }