欢迎来到天天文库
浏览记录
ID:38697809
大小:45.50 KB
页数:4页
时间:2019-06-17
《实验六外观模式的建模方式》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验六一、实验目的1、熟练掌握外观模式的建模方式2、掌握如何应用外观模式编程解决具体问题3、熟练掌握代码模式的建模方式4、掌握如何应用代码模式编程解决具体问题二、实验器材1、计算机一台2、JCreator软件实验内容1、在计算机主机(MainFrame)中,只需要按下主机的开机按钮(on()),即可调用其他硬件设备和软件的启动方法,如内存(Memory)的自检(check())、CPU的运行(run())、硬盘(HardDisk)的读取(read())、操作系统(OS)的载入(load())等,如果某一过程发生错误则计算机启动失败。使用外观没事模拟该过程,绘制类图并编程实现
2、。2、应用软件所提供的桌面快捷方式是快速启动应用程序的代理,桌面快捷方式一般使用一张小图片(Picture)来表示,通过调用快捷方式的run()方法将调用应用软件(Applictation)的run()方法。使用代理模式模拟该过程,试绘制类图并编程实现。三、实验结果关注淘宝店530213程序代码:(1)外观模式代码publicclassComputer{privateCPUcpu;privateHardDiskhardDisk;privateMemorymemory;privateOSos;publicComputer(){this.cpu=newCPU();this.ha
3、rdDisk=newHardDisk();this.memory=newMemory();this.os=newOS();}publicvoidon(){try{memory.check();cpu.run();hardDisk.read();os.load();System.out.println("计算机启动成功!");}catch(Exceptione){System.out.println(e.getMessage());System.out.println("计算机启动失败!");}}}///////////////////////////////////////
4、/////////////publicclassCPU{publicvoidrun(){Randomrandom=newRandom();if(random.nextInt()%10==0){thrownewRuntimeException("CPUsuccess!");}System.out.println("CPUfail!");}}//淘宝店530213////////////////////////////////////////////////////publicclassHardDisk{publicvoidread(){Randomrandom=newRand
5、om();if(random.nextInt()%10==0){thrownewRuntimeException("Harddisksuccess!");}System.out.println("Harddsikfail!");}}////////////////////////////////////////////////////publicclassMemory{publicvoidcheck(){Randomrandom=newRandom();if(random.nextInt()%10==0){thrownewRuntimeException("Memorysu
6、ccess!");}System.out.println("Memoryfail!");}}/////////////////////关注淘宝店530213///////////////////////////publicclassOS{publicvoidload(){Randomrandom=newRandom();if(random.nextInt()%10==0){thrownewRuntimeException("OSsuccess!");}System.out.println("OSfail!");}}//////////////////////////////
7、//////////////////publicclassTest{publicstaticvoidmain(String[]args){Computercomputer=newComputer();computer.on();}}(1)代理模式代码packagecom.puter.pojo;publicinterfaceApplication{voidrun();}packagecom.puter.pojo;publicclassPictureimplementsApplication{Applicationap
此文档下载收益归作者所有