要求:实现显卡、声卡、网卡通过PCI插槽工作

 1 package com.kehou.fit;
 2 
 3 /**
 4  * PCI接口
 5  * @author 
 6  *
 7  */
 8 public interface Pci {
 9     //开始工作
10     String start();
11     
12     //结束工作
13     String stop();
14 }
 1 package com.kehou.fit;
 2 
 3 /**
 4  * 显卡类
 5  * @author 
 6  *
 7  */
 8 public class DisplayCard implements Pci {
 9 
10     public String start() {
11         return"插进显卡,显示特效。。。";
12     }
13 
14     public String stop() {
15         return"拔掉显卡,特效没了。。。";
16     }
17 
18 }
 1 package com.kehou.fit;
 2 
 3 /**
 4  * 网卡类
 5  * @author
 6  *
 7  */
 8 public class NetworkCard implements Pci {
 9 
10     public String start() {
11         return"安装网卡,可以上网了。。。";
12     }
13 
14     public String stop() {
15         return"拔掉网卡,网络没了。。。";
16     }
17 
18 }
 1 package com.kehou.fit;
 2 
 3 /**
 4  * 声卡类
 5  * @author 
 6  *
 7  */
 8 public class SoundCard implements Pci {
 9 
10     public String start() {
11         return"安装声卡,听到声音了。。。";
12     }
13 
14     public String stop() {
15         return"拆除声卡,声音没了。。。";
16     }
17 
18 }
 1 package com.kehou.fit;
 2 
 3 /**
 4  * 装配类
 5  * @author
 6  *
 7  */
 8 public class Fit {
 9     DisplayCard dc;
10     SoundCard sc;
11     NetworkCard nc;
12     
13     public DisplayCard getDc() {
14         return dc;
15     }
16 
17     public void setDc(DisplayCard dc) {
18         this.dc = dc;
19     }
20 
21     public SoundCard getSc() {
22         return sc;
23     }
24 
25     public void setSc(SoundCard sc) {
26         this.sc = sc;
27     }
28 
29     public NetworkCard getNc() {
30         return nc;
31     }
32 
33     public void setNc(NetworkCard nc) {
34         this.nc = nc;
35     }
36 
37     //装配设备
38     public void fitting() {
39         System.out.println("当装配完成后:"+dc.start()+sc.start()+nc.start());
40     }
41     
42     //拆除设备
43     public void dismantling() {
44         System.out.println("拔掉设备后:"+dc.stop()+sc.stop()+nc.stop());
45     }
46 }
 1 package com.kehou.fit;
 2 
 3 public class Test {
 4 
 5     public static void main(String[] args) {
 6         Fit fit=new Fit();
 7         fit.setDc(new DisplayCard());
 8         fit.setNc(new NetworkCard());
 9         fit.setSc(new SoundCard());
10         fit.fitting();
11         fit.dismantling();
12         
13     }
14 
15 }

 

posted on 2018-12-04 21:35  从零开始-白  阅读(550)  评论(0编辑  收藏  举报