zoukankan      html  css  js  c++  java
  • 组装一台电脑

    计算机硬件接口类:

    /**
     * @author Administrator
     *    CPU接口
     */
    public interface CPU {
        public String getBand();
        public String getZhuPin();
    }
    
    
    /**
     * @author Administrator
     *    内存接口
     */
    public interface Dimm {
        public String dimmSize();
    }
    
    
    /**
     * @author Administrator
     *    硬盘接口
     */
    public interface SD {
        public String sdSize();
    }

    硬件生产商类:

    /**
     * @author Administrator
     *    CPU生产商
     */
    public class CPUpro implements CPU{
    
        public String getBand() {
            return "Intel";    
        }
    
        public String getZhuPin() {
            return "3.8GHz";    
        }
    
    }
    
    
    /**
     * @author Administrator
     *    内存生产商
     */
    public class DimmPro implements Dimm{
    
        @Override
        public String dimmSize() {
            // TODO Auto-generated method stub
            return "4GB";
        }
    
    }
    
    
    /**
     * @author Administrator
     *    硬盘生产商
     */
    public class SDpro implements SD{
        @Override
        public String sdSize() {
            return "3000GB";
        }
    }

    计算机类:

    /**
     * @author Administrator
     *    计算机类
     */
    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("计算机的信息如下:");
            System.out.println("CPU的品牌是:"+cpu.getBand()+",主频是:"+cpu.getZhuPin());
            System.out.println("硬盘容量是:"+sd.sdSize());
            System.out.println("内存容量是:"+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;
        }
        
    }

    测试类:

    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();
        }
    }

    运行结果:

  • 相关阅读:
    问题:Failed to execute goal org.apache.maven.plugins:mavencompilerplugin:3.5.1:compile (defaultcompile)
    STL容器的内存分配
    C++中的引用到底是什么
    解决eclipse无法解析shared_ptr
    Deleted pointer causes undefined behaviour
    诞生于饭桌上的jcSQL语言
    状压dp做题笔记
    TC做题笔记
    数据结构做题笔记
    POI做题笔记
  • 原文地址:https://www.cnblogs.com/Dean-0/p/11208720.html
Copyright © 2011-2022 走看看