ImageVerifierCode 换一换
格式:DOC , 页数:23 ,大小:77KB ,
资源ID:152755      下载积分:5 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-152755.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(设计模式课后习题.doc)为本站会员(h****)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

设计模式课后习题.doc

1、 建造者模式 课后第一题: 产品类: public class GamePerson private String face; private String gender; private String cloth; public String getFace() return face; public void setFace(String face) this.face = face; public String getGender() return gender; public void setGender(String gender) this.gender = gender; pub

2、lic String getCloth() return cloth; public void setCloth(String cloth) this.cloth = cloth; 抽象建造类: public abstract class PersonCreate protected GamePerson person=new GamePerson(); public abstract void createFace(); public abstract void createGender(); public abstract void createCloth(); public GamePe

3、rson getPerson() return person; 具体建造者类: public class PersonType1 extends PersonCreate public void createFace() person.setFace(“瓜子脸 “); public void createGender() person.setGender(“美女 “); public void createCloth() person.setCloth(“洛丽塔 “); 具体建造类: public class PersonType2 extends PersonCreate public vo

4、id createFace() person.setFace(“国字脸 “); public void createGender() person.setGender(“帅哥 “); public void createCloth() person.setCloth(“西装革履 “); 指挥者类: public class GamePlayer private PersonCreate pc; public void choseType(PersonCreate pc) this.pc=pc; public GamePerson create() pc.createCloth(); pc.cr

5、eateFace(); pc.createGender(); return pc.getPerson(); 测试类: public class Test public static void main(String args) PersonCreate pc=new PersonType1(); GamePlayer gp=new GamePlayer(); gp.choseType(pc); GamePerson person=gp.create(); System.out.println(“游戏人物特征: “); System.out.println(“长着一张 “+person.getF

6、ace()+“穿着“+person.getCloth()+“的 “+person.getGender(); 课后第二题: 产品类: public class Computer private String cpu; private String storage; public String getCpu() return cpu; public void setCpu(String cpu) this.cpu = cpu; public String getStorage() return storage; public void setStorage(String storage) this

7、.storage = storage; 抽象建造类: public abstract class Factory protected Computer c=new Computer(); public abstract void installCpu(); public abstract void installStorage(); public Computer getComputer() return c; 具体建造者类: public class Desktop extends Factory public void installCpu() c.setCpu(“AMD“); publi

8、c void installStorage() c.setStorage(“8G 内存 “); 具体建造类: public class Laptop extends Factory public void installCpu() c.setCpu(“intel“); public void installStorage() c.setStorage(“1G 内存 “); 指 挥者类: public class User private Factory f; public void buy(Factory f) this.f=f; public Computer con() f.install

9、Cpu(); f.installStorage(); return f.getComputer(); 测试类: public class Test public static void main(String args) Factory f=new Laptop(); User u=new User(); u.buy(f); Computer c=u.con(); System.out.println(c.getCpu()+“ “+c.getStorage(); 单例模式 课后第一题: 懒汉式模式: public class SingletonWindow extends JInternalF

10、rame private static SingletonWindow instance=null; private SingletonWindow() super(“内部窗口 “,true,true,true); System.out.println(“创建了一个内部窗体 “); public static SingletonWindow getInstance() if(instance=null) instance=new SingletonWindow(); else System.out.println(“已经创建了一个内部窗体! “); return instance; 测试类:

11、public class Main extends JFrame private static final long serialVersionUID = 1L; private JButton btnAdd; private JPanel btnpl; private JDesktopPane dtp; private JInternalFrame itf; public Main() this.setSize(new Dimension(600, 700); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setResizable(fa

12、lse); this.setVisible(true); this.setLocationRelativeTo(this); this.setTitle(“实验 2“); this.setLayout(null); this.dtp=new JDesktopPane(); this.dtp.setBounds(new Rectangle(0, 0, 600, 600); this.btnpl=new JPanel(); this.btnpl.setBounds(new Rectangle(0, 600, 600, 100); this.btnAdd=new JButton(“添加一个内部窗体

13、“); this.btnAdd.setBounds(new Rectangle(10, 10, 150, 30); this.add(dtp); this.add(btnpl); this.btnpl.add(btnAdd); this.btnAdd.addActionListener(new ActionListener() public void actionPerformed(ActionEvent arg0) itf=SingletonWindow.getInstance(); itf.setSize(200, 200); itf.setVisible(true); dtp.add(i

14、tf); ); public static void main(String args) new Main(); 适配器模式 课后第一题 目标抽象类: public abstract class Robot public abstract void run(); public abstract void cry(); 适配者类: public class Dog public void run() System.out.println(“狗跑 “); public class Bird public void cry() System.out.println(“鸟叫 “); 适配器类: pub

15、lic class RobotAdapter extends Robot private Bird bird; private Dog dog; public RobotAdapter(Bird bird,Dog dog) this.bird=bird; this.dog=dog; public void run() System.out.print(“机器人学 “); dog.run(); public void cry() System.out.print(“机器人学 “); bird.cry(); 测试类: public class Test public static void mai

16、n(String args) Bird bird=new Bird(); Dog dog=new Dog(); RobotAdapter adapter=new RobotAdapter(bird, dog); adapter.run(); adapter.cry(); 组合模式 课后习题一 public abstract class MyElement public abstract void eat(); public abstract void add(MyElement element); public abstract void remove(MyElement element);

17、public class Apple extends MyElement public void eat() System.out.println(“吃苹果 “); public void add(MyElement element) public void remove(MyElement element) public class Banana extends MyElement public void eat() System.out.println(“吃香蕉 “); public void add(MyElement element) public void remove(MyElem

18、ent element) public class Pear extends MyElement public void eat() System.out.println(“吃梨子 “); public void add(MyElement element) public void remove(MyElement element) public class Plate extends MyElement private ArrayList list=new ArrayList(); public void eat() for (Object object : list) (MyElement

19、)object).eat(); public void add(MyElement element) list.add(element); public void remove(MyElement element) list.remove(element); 测试类: public class Client public static void main(String args) MyElement obj1,obj2,obj3,obj4,obj5; Plate plate1,plate2,plate3; obj1=new Apple(); obj2=new Pear(); obj3=new

20、Banana(); plate1=new Plate(); plate1.add(obj1); plate1.add(obj2); plate1.add(obj3); obj4=new Apple(); obj5=new Banana(); plate2=new Plate(); plate3=new Plate(); plate2.add(obj4); plate2.add(obj5); plate3.add(plate1); plate3.add(plate2); plate3.eat(); 课后习题二 public abstract class AbstractFile public a

21、bstract void add(AbstractFile file ); public abstract void delete(AbstractFile file); public abstract void lookThrough(); public abstract String getfileName(); public class ImageFile extends AbstractFile private String fileName; public ImageFile(String fileName) this.fileName=fileName; public void a

22、dd(AbstractFile file) public void delete(AbstractFile file) public void lookThrough() public String getfileName() return fileName; public class TextFile extends AbstractFile private String fileName; public TextFile(String fileName) this.fileName=fileName; public void add(AbstractFile file) public vo

23、id delete(AbstractFile file) public void lookThrough() public String getfileName() return fileName; public class VedioFile extends AbstractFile private String fileName; public VedioFile(String fileName) this.fileName=fileName; public void add(AbstractFile file) public void delete(AbstractFile file) public void lookThrough() public String getfileName() return fileName; public class Folder extends AbstractFile private ArrayList list=new ArrayList(); private String fileName; public Folder(String fileName) this.fileName=fileName; public void add(AbstractFile file) list.add(file);

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。