欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    面向对象系统分析和设计综合实验报告4.doc

    • 资源ID:1304994       资源大小:334KB        全文页数:18页
    • 资源格式: DOC        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    面向对象系统分析和设计综合实验报告4.doc

    1、西南科技大学计算机学院 面向对象系统分析和设计实验报告实验名称:实验4 设计模型实验2 学期:2017-2018学年 第二学期 一、实验目的1熟练使用面向对象设计原则对系统进行重构;2熟练使用面向对象编程语言(JAVA或C+)实现几种常见的设计模式,包括单例模式、策略模式、装饰模式和适配器模式,理解每一种设计模式的模式动机,掌握模式结构,学习如何使用代码实现这些模式。二、实验要求1. 选择合适的面向对象设计原则对系统进行重构,正确无误地绘制重构之后的类图;2. 结合实例,正确无误地绘制单例模式、策略模式、装饰模式和适配器模式的结构图;3. 实现单例模式、策略模式、装饰模式和适配器模式,代码运行

    2、正确无误。三、实验内容1. 现实生活中,居民身份证号码具有唯一性,同一个人不允许有多个身份证号码,第一次申请身份证时将号码分配给居民,如果之后因为遗失等原因补办时,还是使用原来的身份证号码,不会产生新号码,现使用单例模式模拟该场景。1) 类图2) 实现代码:public class IdClient public static void main(String args) IdentityCardNo.getInstance();IdentityCardNo.getInstance();package Refactoring1;public class IdentityCardNo priva

    3、te static IdentityCardNo instance;private String no;private IdentityCardNo() public static IdentityCardNo getInstance() if (instance = null) System.out.println(第一次办理身份证,分配新号码);instance = new IdentityCardNo();instance.setNo(No6000654321);System.out.println(身份证号码为: + instance.getNo(); else System.out.

    4、println(重复办理身份证,获取旧号码!);return instance;public String getNo() return no;public void setNo(String no) this.no = no;2. 每一麻将局都有两个骰子,因此骰子就应当是双例类。现使用多例模式模拟该场景。1) 类图2) 实现代码:import java.util.Date;import java.util.Random;public class Dice private static Dice die1 = new Dice();private static Dice die2 = new

    5、Dice();private Dice() public static Dice getInstance(int whichOne) if (whichOne = 1) return die1; else return die2;public synchronized int dice() Date d = new Date();Random r = new Random(d.getTime();int value = r.nextInt(); value = Math.abs(value); value = value % 6; value += 1;return value;import

    6、java.util.Random;import java.util.Date;public class DiceClient private static Dice die1, die2;public static void main(String args) die1 = Dice.getInstance(1);die2 = Dice.getInstance(2);System.out.println(第一骰子骰出: + die1.dice();System.out.println(第二骰子骰出: + die2.dice();3. 某软件公司为某电影院开发了一套影院售票系统,在该系统中需要为

    7、不同类型的用户提供不同的电影票(MovieTicket)打折(Discount)方式,具体打折方案如下: 学生凭学生证可享受票价8折优惠; 年龄在10周岁及以下的儿童可享受每张票减免10元的优惠(原始票价需大于等于20元); 影院VIP用户除享受票价半价优惠外还可进行积分,积分累计到一定额度可换取电影院赠送的奖品。该系统在将来可能还要根据需要引入新的打折方式。试使用策略模式设计并编程模拟实现该影院售票系统。1) 类图2) 实现代码:public interface Discount public double calculate(double price); public class Movi

    8、eTicket private double price; private Discount discount; /维持一个对抽象折扣类的引用 public void setPrice(double price) this.price = price; /注入一个折扣类对象 public void setDiscount(Discount discount) this.discount = discount; public double getPrice() /调用折扣类的折扣价计算方法 return discount.calculate(this.price); /VIP会员票折扣类:具体策

    9、略类 public class VIPDiscount implements Discount public double calculate(double price) System.out.println(VIP票:); System.out.println(增加积分!); return price * 0.5; /学生票折扣类:具体策略类 public class StudentDiscount implements Discount public double calculate(double price) System.out.println(学生票:); return price

    10、* 0.8; /儿童票折扣类:具体策略类 public class ChildrenDiscount implements Discount public double calculate(double price) System.out.println(儿童票:); return price - 10; public class MoviceClient public static void main(String args) MovieTicket mt = new MovieTicket(); double originalPrice = 60.0; double currentPric

    11、e; mt.setPrice(originalPrice); System.out.println(原始价为: + originalPrice); System.out.println(-); Discount discount =new VIPDiscount(); /vip 用户 mt.setDiscount(discount); /注入折扣对象 currentPrice = mt.getPrice(); System.out.println(折后价为: + currentPrice); discount =new StudentDiscount(); /学生用户 mt.setDiscou

    12、nt(discount); /注入折扣对象 currentPrice = mt.getPrice(); System.out.println(折后价为: + currentPrice); discount =new ChildrenDiscount(); /儿童用户 mt.setDiscount(discount); /注入折扣对象 currentPrice = mt.getPrice(); System.out.println(折后价为: + currentPrice); 3) 实现结果:4. 某软件公司欲开发一款飞机模拟系统,该系统主要模拟不同种类飞机的飞行特征与起飞特征,需要模拟的飞机种

    13、类及其特征如表1所示:表1 飞机种类及特征一览表飞机种类起飞特征飞行特征直升机(Helicopter)垂直起飞(VerticalTakeOff)亚音速飞行(SubSonicFly)客机(AirPlane)长距离起飞(LongDistanceTakeOff)亚音速飞行(SubSonicFly)歼击机(Fighter)长距离起飞(LongDistanceTakeOff)超音速飞行(SuperSonicFly)鹞式战斗机(Harrier)垂直起飞(VerticalTakeOff)超音速飞行(SuperSonicFly)为将来能够模拟更多种类的飞机,试采用策略模式设计并模拟实现该飞机模拟系统。1) 类

    14、图2) 实现代码:public class plane private state state;/状态public void settakeoffFeatures(state tFeatures)this.state = tFeatures;public void setplanetype(String type) if(type=直升机) state=new Helicopter(); else if(type=客机) state=new AirPlane(); else if(type=歼击机) state=new Fighter(); else if(type=鹞式战斗机) state=

    15、new Harrier(); else state=null; public void takeoff()state.takeOff();public void fly()state.fly();public class AirPlane implements stateOverridepublic String takeOff() System.out.println(长距离起飞);return 长距离起飞;Overridepublic String fly() System.out.println(亚音速飞行);return 亚音速飞行;public class Fighter imple

    16、ments stateOverridepublic String takeOff() System.out.println(长距离起飞);return 长距离起飞;Overridepublic String fly() System.out.println(超亚音速飞行);return 超音速飞行;public class Harrier implements stateOverridepublic String takeOff() System.out.println(垂直起飞);return 垂直起飞;Overridepublic String fly() System.out.print

    17、ln(超亚音速飞行);return 超音速飞行;public class Helicopter implements stateOverridepublic String takeOff() System.out.println(垂直起飞);return 垂直起飞;Overridepublic String fly() System.out.println(亚音速飞行);return 亚音速飞行;public interface state public String takeOff();/起飞public String fly();/飞行public class Client public

    18、static void main(String args) plane plane = new plane();plane.setplanetype(歼击机);plane.takeoff();plane.fly();3) 实现结果:5. 儿子、妈妈、父亲三人合作画一幅画,儿子负责画出一朵花的轮廓,妈妈负责涂上颜色、父亲负责将画裱在画框里。现请使用装饰模式模拟这个过程。1) 类图2) 实现代码:public interface painting public String Draw();public class Son implements paintingOverridepublic Stri

    19、ng Draw() System.out.println(儿子用笔画出了花的轮廓);return 儿子用笔画出了花的轮廓;public class Father implements painting private painting painting;/被装饰者 public Father(painting painting) this.painting =painting; private Father() public void paint() /爸爸装饰者做的职责 System.out.println(爸爸正在做上画框前的准备工作); painting.Draw();/爸爸装饰者做职责

    20、 System.out.println(父亲将画裱在画框里); Overridepublic String Draw() System.out.println(父亲将画裱在画框里);return 父亲将画裱在画框里;public class Mother implements paintingprivate painting painting;/被装饰者public Mother(painting painting) this.painting =painting;private Mother() public void paint() System.out.println(妈妈正在做给画上颜

    21、色前的准备工作。);painting.Draw();/妈妈装饰者做的职责System.out.println(妈妈给画上好了颜色);Overridepublic String Draw() System.out.println(妈妈给画上好了颜色);return 妈妈给画上好了颜色;public class Client public static void main(String args)painting painting =new Son();painting.Draw(); painting = new Mother(painting);painting.Draw();painting

    22、 = new Father(painting);painting.Draw(); 3) 实现结果:6. 某公司想通过网络传输数据,但是担心文件被窃取。他们的所有数据都采用字符的方式传送。现在他们开发了一个数据加密模块,可以对字符串进行加密,以便数据更安全地传送。最简单的加密算法通过对字母向后移动6位来实现,同时还提供了稍复杂的逆向输出加密,还提供了更为高级的求模加密,让每一位与6求模。用户先使用最简单的加密算法对字符串进行加密,再对加密之后的结果使用复杂加密算法进行二次加密,再对二次加密结果用高级加密算法进行第三次加密。现请使用装饰模式模拟这个过程。1) 类图2) 实现代码:public cl

    23、ass ConcreteEncrypt implements EncryptComponetprivate EncryptComponet encryptComponet; public ConcreteEncrypt(EncryptComponet encryptComponet) super(); this.encryptComponet = encryptComponet; public void encrypt() encryptComponet.encrypt(); public interface EncryptComponet public abstract void encry

    24、pt();public class RawData implements EncryptComponetpublic void encrypt() System.out.println(这是要发送的数据); public class ReversEncrypt implements EncryptComponetpublic ReversEncrypt(EncryptComponet encryptComponet) addReservesEncrypt(); private void addReservesEncrypt() System.out.println(反向加密); Overrid

    25、epublic void encrypt() public class SuperEncrypt implements EncryptComponetpublic SuperEncrypt(EncryptComponet encryptComponet) addSuperEncrypt(); private void addSuperEncrypt() System.out.println(最高加密算法); Overridepublic void encrypt() public class TranslateEncrypt implements EncryptComponetpublic TranslateEncrypt(EncryptComponet encryptComponet) addTranslateEncrypt(); private void addTranslateEncrypt() System.out.println(移动加密); Ove


    注意事项

    本文(面向对象系统分析和设计综合实验报告4.doc)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开