Java-采用面向接口编程思想组装一台计算机
1. CPU Interface
package cn.interfaceWork.output;
public interface Cpu {
String cpuInfo();
String cpuBrandInfo();
}
2. Memory Interface
package cn.interfaceWork.output;
public interface Memory {
String memoryInfo();
}
3. HardDisk Interface
package cn.interfaceWork.output;
public interface HardDisk {
String hardDiskInfo();
}
4. MasterComputer Class
package cn.interfaceWork.output;
public class MasterComputer implements Memory, HardDisk,Cpu{
@Override
public String cpuInfo(){
return "1199999GHz";
}
@Override
public String cpuBrandInfo(){
return "Intel i10";
}
@Override
public String memoryInfo(){
return "64G";
}
@Override
public String hardDiskInfo(){
return "1T";
}
}
5. ComputerInfo Class
package cn.interfaceWork.output;
public class ComputerInfo {
public MasterComputer mc = new MasterComputer();
public void show() {
System.out.println("计算机信息如下: ");
System.out.println("CPU的品牌是: "+mc.cpuBrandInfo()+"主频是: "+mc.cpuInfo());
System.out.println("磁盘容量: "+mc.hardDiskInfo()+"内存容量是:"+mc.memoryInfo());
}
public static void main(String[] args) {
ComputerInfo start = new ComputerInfo();
start.show();
}
}