




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、accp v4.0动物特性的面向对象描述 accp v4.02 问题描述q 动物特性描述q 狗生活在陆地上(是一种陆生动物),既是哺乳类的也是肉食性的。狗通常的时候和人打招呼会通过“摇摇尾巴”,在被抚摸感到舒服的时候,会“旺旺叫”,而在受到惊吓情绪烦躁时,会发出“呜呜”声;q 猫也生活在陆地上(是一种陆生动物),既是哺乳类的也是肉食性的。猫通常的时候和人打招呼会发出“喵”的声音,在被抚摸情绪很好时,会发出“咕噜咕噜”声,而在受到惊吓时,会发出“嘶嘶”声;q 青蛙是一种两栖动物(既是水生动物也是陆生动物),既不是哺乳类的也不是肉食性的,属于卵生。当青蛙情绪好的时候,会在岸边“呱呱呱”的唱歌,而在
2、受到惊吓时,会“扑通一声跳入水中”; accp v4.03问题分析q首先需要抽取问题描述中对象q分析每个对象所具有的特征q分析每个对象所发出的动作q从这些对象的特征中,抽取类的属性和方法q分析类之间的关系,画出类结构图accp v4.04难点分析-1抽象类和对象的基本方法:q 抽取对象的基本的方法:找出句子中所使用的名词 例如:在句子“小猫喵喵叫”中,我们能够确定一个对象:猫;q 确定对象发出的行为动作的基本的方法:找出句子中的动词 例如:“旺旺叫”、“喵喵叫”都属于对象发出的动作;q 确定对象的属性或者特征的基本的方法:找出句子中的形容词 例如:“哺乳性的”“肉食性的”“卵生的”等等;q “
3、是”的关系一般抽象为继承 例如:狗是一种动物,意味着:“狗”类 继承自“动物”类;q “有”的关系一般抽象为类的属性 例如:动物都有情绪,意味着:“情绪”是“动物”类的一个属性;accp v4.05难点分析-2 dog:int numberoflegsdog( )sayhello( )sayhello(int newvalue)getnumberoflegs( )cat:int numberoflegscat( )sayhello( )sayhello(int newvalue)getnumberoflegs( )frog:int numberoflegsfrog( )sayhello( )s
4、ayhello(int newvalue)getnumberoflegs( )hasgills( )layseggs( )wateranimal:hasgills( )layseggs( )landanimal:getnumberoflegs( )animal:boolean mammalboolean carnivorousint moodismammal( )iscarnivorous( )setmood(int newvalue)getmood( )sayhello( )sayhello(int moodval)accp v4.06阶段划分q第一阶段(60分钟):不考虑情绪影响动物打招
5、呼的方式q第二阶段(40分钟):考虑情绪影响动物打招呼 的方式q第三阶段(60分钟):考虑陆生动物和水生动物accp v4.07第一阶段q第一阶段(60分钟):不考虑情绪影响动物打招呼的方式q编写animal类,没有mood属性,只有一种sayhello方法;q编写dog类、cat类和frog类,分别继承自animal类,实现与animal类不同的功能;q编写main方法,分别实例化以上三个类的三个对象,测试类方法实现的正确性;q要求学员自己动手编码,在编码的过程中解答学员提出的问题accp v4.08阶段检查q针对第一阶段抽查学员的编码结果q教员给出点评accp v4.09第一阶段标准代码演
6、示q第一阶段编码的结果:abstract class animal protected boolean mammal = true; protected boolean carnivorous = true; public boolean ismammal() return(mammal); public boolean iscarnivorous() return(carnivorous); abstract public string sayhello();abstractabstractprotectedprotectedclass dog extends animal public s
7、tring sayhello() return(摇摇尾巴摇摇尾巴);class cat extends animal public string sayhello() return(喵喵叫喵喵叫);class frog extends animal public frog() mammal = false; carnivorous = false; public string sayhello() return(呱呱呱呱呱呱); extendsextendsextendspublic string sayhello() return(摇摇尾巴);public string sayhello()
8、 return(喵喵叫);public string sayhello() return(呱呱呱); public frog() mammal = false; carnivorous = false; public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog(); if(animal1.ismammal() system.out.println(狗是哺乳动物狗是哺乳动物); else
9、 system.out.println(狗不是哺乳动物狗不是哺乳动物); if(animal1.iscarnivorous() system.out.println(狗是肉食动物狗是肉食动物); else system.out.println(狗不是肉食动物狗不是肉食动物); system.out.println(狗通常的情况下,和人打招呼的方式为:狗通常的情况下,和人打招呼的方式为: +animal1.sayhello(); dog animal1 = new dog();cat animal2 = new cat();frog animal3 = new frog();animal1.is
10、mammal()animal1.iscarnivorous()animal1.sayhello()accp v4.010第二阶段q 第二阶段(40分钟):考虑情绪影响动物打招 呼的方式q扩充animal类、dog类、cat类和frog类,增加 animal类的mood属性,并实现sayhello方法的多态性;q扩充main方法;q 要求学员自己动手编码,在编码的过程中解答 学员提出的问题accp v4.011阶段检查q针对第二阶段抽查学员的编码结果q教员给出点评accp v4.012第二阶段标准代码演示q第二阶段的编码结果:abstract class animal public static
11、 final int scared = 1;/情绪不好,烦躁 public static final int comforted = 2;/情绪好 protected boolean mammal = false; protected boolean carnivorous = false; protected int mood = comforted;/情绪属性 public boolean ismammal() return(mammal); public boolean iscarnivorous() return(carnivorous); abstract public string
12、 sayhello(); abstract public string sayhello(int moodval); public void setmood(int newvalue) mood = newvalue; public int getmood() return(mood); public static final int scared = 1;/情绪好public static final int comforted = 2;/情绪不好,烦躁protected int mood = comforted;/情绪属性public void setmood(int newvalue)
13、mood = newvalue; public int getmood() return(mood); abstract public string sayhello();abstract public string sayhello(int moodval);class dog extends animal public string sayhello() return(摇摇尾巴); public string sayhello(int moodval) this.setmood(moodval); switch (mood) case scared: return(呜呜叫); case c
14、omforted: return(旺旺旺叫); return(摇摇尾巴); class cat extends animal public string sayhello(int moodval) class frog extends animal public string sayhello(int moodval) public string sayhello(int moodval) this.setmood(moodval); switch (mood) case scared: return(呜呜叫); case comforted: return(旺旺旺叫); return(摇摇尾
15、巴); public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog(); system.out.println(狗通常的情况下,和人打招呼的方式为: +animal1.sayhello(); system.out.println(狗被抚摸情绪好的时候,打招呼的方式是: +animal1.sayhello(animal.comforted); system.out.println(狗烦躁的
16、时候,会: +animal1.sayhello(animal.scared); system.out.println(狗通常的情况下,和人打招呼的方式为: + animal1.sayhello();system.out.println(狗被抚摸情绪好的时候,打招呼的方式是: + animal1.sayhello(animal.comforted);system.out.println(狗烦躁的时候,会: + animal1.sayhello(animal.scared);accp v4.013第三阶段q第三阶段(60分钟):考虑陆生动物和水生动物q定义landanimal接口和waterani
17、mal接口;q扩充dog类、cat类和frog类,使其实现相应的接口;q扩充main方法;q要求学员自己动手编码,在编码的过程中解答学员提出的问题accp v4.014阶段检查q 针对第二阶段抽查学员的编码结果q 抽查学员编写的完整代码,要求学员上台讲解, 并演示运行结果q 教员给出点评accp v4.015第三阶段标准代码演示q 第三阶段的编码结果:interface landanimal /陆生动物接口 public int getnumberoflegs(); /返回有多少只脚interface wateranimal /水生动物接口 public boolean getgillflag
18、(); /返回是否有腮 public boolean getlayseggs(); /返回是否产卵interfaceinterfaceclass dog extends animal implements landanimal private int numberoflegs = 4; public int getnumberoflegs() return(numberoflegs); / 实现 landanimal接口class frog extends animal implements landanimal, wateranimal private boolean gillflag =
19、true; private boolean layseggs = true; private int numberoflegs = 4; private boolean tailflag = true; / 实现 wateranimal接口 public boolean getgillflag() return(gillflag); public boolean getlayseggs() return(layseggs); / 实现 landanimal接口 public int getnumberoflegs() return(numberoflegs); implements landa
20、nimalimplements landanimal, wateranimalprivate boolean gillflag = true;private boolean layseggs = true;private int numberoflegs = 4;private boolean tailflag = true;/ 实现 wateranimal接口public boolean getgillflag() return(gillflag); public boolean getlayseggs() return(layseggs); / 实现 landanimal接口 public int getnumberoflegs() return(numberoflegs); public class helloworld public static void main(string args) dog animal1 = new dog(); cat animal2 = new cat(); frog animal3 = new frog()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国网吧专用电脑项目创业计划书
- 中国即食海蜇加工项目创业计划书
- 中国鸡翅项目创业计划书
- 中国三叶漆属项目创业计划书
- 中国B超机项目创业计划书
- 中国经济藻项目创业计划书
- 2025建筑工程专业分包劳务分包合同范本
- 湖北省农业项目创业计划书
- 生活服务平台个性化定制合同
- 安全禁区测试题目及答案
- 北京市海淀区2024-2025学年七年级下学期期中地理试题(解析版)
- 2025年中考押题预测卷:生物(福建卷01)(考试版)
- 人工智能提示词工程师试题含答案
- 2025-2030中国风能风电行业市场深度调研及竞争格局与投资前景研究报告
- 人力资源管理2025年考试试卷及答案
- 安徽省合肥市庐江县2023-2024学年七年级下学期6月期末数学试题
- DB31/T 920-2015产业园区服务规范
- 2025年大学辅导员招聘考试题库:学生综合素质评价体系与辅导员思想政治教育试题
- 2025年高纯活性氧化镁项目市场调查研究报告
- 个体商合伙协议书
- 商场消防设施管理与维护措施
评论
0/150
提交评论