文档库 最新最全的文档下载
当前位置:文档库 › 面向对象强化训练1

面向对象强化训练1

面向对象强化训练1
面向对象强化训练1

【练习题】综合题

题目:品尝饮料(必做)

时间:2006-06-18

一、语言和环境

1.实现语言:Java

2.环境要求:JDK1.4或以上版本及其联机帮助文档

二、要求

1、输入需要的饮料,输出该饮料类型的味道,如:当命令行

参数为1时,结果见图1:

图1

2、如果没有该种饮料,结果见如图2:

图2

三、推荐实现步骤

1、建立一个Java抽象类Drink,应当:

a、声明一个抽象方法taste(),该方法负责输出饮料的味道;

b、声明int型常量来代表不同的饮料类型(咖啡、啤酒、牛

奶),如:

c、声明静态方法getDrink(int drinkType),根据传入的参

数创建不同的饮料对象,并返回该对象,建议使用switch

语句。该方法要求声明DrinkNotFoundException(自定义),

当没有相对应的饮料类型时,抛出该异常。

2、建立Drink的具体子类:

a、分别建立Drink的子类:Coffee(代表咖啡),Beer(代

表啤酒),Milk(代表牛奶);

b、实现taste()方法,要求在控制台打印各自的味道特征。

3、建立异常类DrinkNotFoundException

a、继承Exception

b、在Drink的方法getDrink(int drinkType)中声明引发

DrinkNotFoundException异常,当传入的参数没有相对应

的饮料类型时,抛出异常。

c、在使用getDrink方法的类中捕捉该异常。

4、建立Test测试类,测试以上内容的正确性

a、编写main方法,通过命令行传参的方式传入某种饮料的

类型。

b、在main方法中,调用Drink类的getDrink方法,获得相

应的饮料对象。注意捕获DrinkNotFoundException。

c、然后调用该饮料对象的taste()方法,输出该饮料的味道。

5、编译程序,并运行。

【练习题】抽象类、继承、接口综合(必做)

设计一个系统:

XXX门的实现过程:

流程:

设计一张抽象的门Door,那么对于这张门来说,就应该拥有所有门的共性,开门openDoor()和关门closeDoor();然后对门进行另外的功能设计,防盗--theftproof()、防水--waterproof()、防弹--bulletproof()、防火、防锈……

要求:利用继承、抽象类、接口的知识设计该门

高级设计:装饰模式---假设这些步骤都是通过一个抽象的设备(类)来实现

练习题(选作)

设计一个词典类Dic,每个单词包括英文单词及对应的中文含义,并有一个英汉翻译成员函数,通过查词典的方式将一段英语翻译成对应的汉语。

思路:字典项类DicItem包括EngLish(英语单词)、Chinese(对应中文含义)数据成员,字典类包括一个字典项类的列表,包含Add()(添

加单词)和trans(英汉翻译)成员函数。

邹申版英语写作教程1课后答案-UNIT 2-keys

P21 Pronouns 1)She me 2)Me 3)Him 4)She 5)Who 6)Whoever 7)Who/whom 8)Whom P25 2 1)play a minor role 2) That’s Greek to me 3) belated action 4)Where there is smoke there is fire 5) be a utility man 6)walk into the trap 7) one’s face glowing with health 3 1)We must practice economy. We must reduce unnecessary expenditures. 2)It is essential to control environmental pollution. 3)We must arrive at the station on time. 4)Financial expenditures should be arranged in order of priority. 5)We should speed up construction of urban housing, so as to improve the housing conditions. 6)Private capital has to meet two conditions. First, the profits must be legal. Second, they must be excessive. 7)During the period of the Eleventh Five-Year Plan we must never neglect grain production. Instead, we must steadily increase it. P26 5 1)me 2)who 3)I 4)me/myself 5)me 6)each other’s 7)who 8)us 9)whom 10)Some 11)one’s 12)his 13)his 14)his his

综合教程1课后答案

综合教程1课后答案 Unit 1 College Life Enhance Your Language Awareness Words in Action 1. (P.23) 1) deliver 2) polish 3) available 4) latter 5)file 6) thrive 7) undertook 8) practical 9) fulfill 10) perceived 11) accumulated 12) multiplied 2. (P.24) 1)compromise 2) self-induced 3) steered 4) frame 5)demonstrated 6) employ 7) promote 8) impressed 9)contribution 10) deliberately 11) financial 12) economic 3.(P.24) 1)makes a point of 2) refresh my memory 3) lead to 4) at hand 5) working out 6) under pressure 7) Last but not least 8) down 9) In addition to 10) were involved 11) in other words 12) pointed out 13) pay off 4. (P.25) 1) scored 2) scheduled 3) assigned 4) motivated 5) crucial 6) promote 7) perform 8) debate 9) scanned 10) devised 11) advocated 12) clarify 13) priorities 14) compromised 15) context 16) undertook Final sentence: academic excellence Increasing Your Word Power 1.( P.26~27) 1)principal/ major 2) top 3) major 4) top 5)principal 6) major 7) schedule 8)advocate/have advocated 9) top 10) approach 11)blame 12) major/ principal 13) advocate 14) schedule 15)blame 16) approaching 17) pressure 18) pace 19)pressured 20) pace Cloze (P.31) 1)academic 2) priorities 3) conducted 4) principles 5)begin 6) priority 7) compromised 8) addition 9)filling 10) Speaking 11) formula 12)Participation/ Participating 13) based 14) least 15)way 16) pressure

《面向对象程序设计》实验指导书

《面向对象程序设计》课程实验指导书

实验一 Java开发环境的安装与配置 一、实验目的: 1. 掌握JDK、Eclipse的安装步骤。 2. 理解环境变量PATH, CLASSPATH的作用,以及Eclipse的配置。 3. 熟悉Eclipse的编辑、编译与调试环境,编写简单的Application程序 编译执行并完成调试。 二、实验内容: 熟悉JDK的安装和配置,学习如何编写并运行简单的Application程序 (能输出一条简单的问候信息); 三、实验要求: 1. 能正确地安装JDK 2. 熟悉环境变量PATH, CLASSPATH设置方法,熟悉编辑环境 3. 调试程序、编译,运行后得到正确的结果 四、实验步骤: 1.从https://www.wendangku.net/doc/5b13679758.html,/technetwork/java/index.html上下载最新版本的JDK,并安装。 2.设置环境变量PATH, CLASSPATH, 使得Java程序能正确编译和执行。 3.在Eclipse环境下编写一个HelloWorld.java程序, (1)在主方法static public void main(String[ ] args)中调用System. out.println()方法,使程序输出一条问候信息; (2) 编译运行程序,观察运行情况和输出结果。(使用JDK环境,调用 javac.exe和java.exe编译和执行程序)

实验二 Java语言基础 一、实验目的: 熟悉Java基本语法,基本数据类型,各种运算符及表达式的使用,掌握运算符优先级,熟悉使用Java的选择语句,循环语句。 二、实验内容: 1.编写Java Application程序,输出1900年到2000年之间的所有润年。 (闰年的判断条件:能被4整除且不能被100整除,或能被400整除); 2.金字塔:Pyramid.java 在屏幕上显示一个由星型符号“*”组成的金字塔图案,示例如下: * *** ***** ******* 要求:金字塔高度h,可以由用户设置。 三、实验要求: 1. 正确使用Java语言的选择语句,循环语句; 2. 调试程序、编译,运行后得到正确的结果 3.写出实验报告。要求记录编译和执行Java程序当中的系统错误信息提成 示,并给出解决办法。 四、实验步骤: 1.编写主类; 2.在static public void main(String[ ] args)方法中加入实现要求功能 的代码,主要步骤如下: (第一题)从1900到2000循环,按照闰年的判断条件是则输出1900年到2000年之间的所有润年。 (第二题)允许用户设置金字塔高度。 4. 编译运行程序,观察输出结果是否正确。

邹申版英语写作教程1课后答案-unit6-keys

UNIT 6 P75 1)The enraged father threatened to throw the screaming boy out of the room. 2)You can use the frequently used method. 3)Tommy, filled with despair, left the office. 4)Smiling through the window, the girl is enjoying one of the happiest days in her life. 5)The boy was sitting at his desk, his feet gently tapping the floor. 6)The computers damaged by an unknown virus, the employees are happy to take the day off. P76 Task1 Sentences 1) and 2) participles as attributes Sentences 3) and 4) participles to indicate simultaneous actions Sentences 5) and 6) as absolute constructions P78 1. smiling 2. Reading 3. Swimming 4. competing broken informing 8. Having exhausted relieved P80 Task 2 1.The computer bought last week brings happiness to everyone in my family. 2.Being back in my hometown, I didn’t know that my professor had \assigned another 5000-word paper. 3.Standing in front of the picture painted by a post-impressionist, many people pretended that they could understand it. 4.Looking out of the window of the train, the boy was amused by the power lines dancing up and down in the air. P81 Classroom Activities Task 1 1.Kate fell asleep when reading Bo b’s letter. 2.She started to chat with her friend after finish/ having finished her work. 3.Although having seen it a thousand and one times, the old man still watches the video from time to time. 4.Though closely watched by the guards, the prisoner plans to escape. 5.It is believed that if read many times, an article will naturally be understood. 6.if buying more, you can pay less. P82 B a. 2) P83 Classroom activities Task 1 1)Thinking about her kid at home, Judy… 2)Racing along the street, the car sent… 3)Born in educated in …, she is now working …

全新版大学英语_综合教程1_课后翻译与答案

《全新版大学英语综合教程1 课后翻译及答案》Unit 1 Growing Up 为自己而写 ——拉塞尔·贝克 从孩提时代,我还住在贝尔维尔时,我的脑子里就断断续续地转着当作家的念头,但直等到我高中三年级,这一想法才有了实现的可能。在这之前,我对所有跟英文课沾边的事都感到腻味。我觉得英文语法枯燥难懂。我痛恨那些长而乏味的段落写作,老师读着受累,我写着痛苦。弗利格尔先生接我们的高三英文课时,我就准备着在这门最最单调乏味的课上再熬上沉闷的一年。弗利格尔先生在学生中以其说话干巴和激励学生无术而出名。据说他拘谨刻板,完全落后于时代。我看他有六七十岁了,古板之极。他戴着古板的毫无装饰的眼镜,微微卷曲的头发剪得笔齐,梳得纹丝不乱。他身穿古板的套装,领带端端正正地顶着白衬衣的领扣。他长着古板的尖下巴,古板的直鼻梁,说起话来一本正经,字斟句酌,彬彬有礼,活脱脱一个滑稽的老古董。 我作好准备,打算在弗利格尔先生的班上一无所获地混上一年,不少日子过去了,还真不出所料。后半学期我们学写随笔小品文。弗利格尔先生发下一张家庭作业纸,出了不少题目供我们选择。像"暑假二三事"那样傻乎乎的题目倒是一个也没有,但绝大多数一样乏味。我把作文题带回家,一直没写,直到要交作业的前一天晚上。我躺在沙发上,最终不得不面对这一讨厌的功课,便从笔记本里抽出作文题目单粗粗一看。我的目光落在"吃意大利细面条的艺术"这个题目上。

这个题目在我脑海里唤起了一连串不同寻常的图像。贝尔维尔之夜的清晰的回忆如潮水一般涌来,当时,我们大家一起围坐在晚餐桌旁——艾伦舅舅、我母亲、查理舅舅、多丽丝、哈尔舅舅——帕特舅妈晚饭做的是意大利细面条。那时意大利细面条还是很少听说的异国食品。多丽丝和我都还从来没吃过,在座的大人也是经验不足,没有一个吃起来得心应手的。艾伦舅舅家诙谐有趣的场景全都重现在我的脑海中,我回想起来,当晚我们笑作一团,争论着该如何地把面条从盘子上送到嘴里才算合乎礼仪。 突然我就想描述那一切,描述当时那种温馨美好的气氛,但我把它写下来仅仅是想自得其乐,而不是为弗利格尔先生而写。那是我想重新捕捉并珍藏在心中的一个时刻。我想重温那个夜晚的愉快。然而,照我希望的那样去写,就会违反我在学校里学的正式作文的种种法则,弗利格尔先生也肯定会打它一个不及格。没关系。等我为自己写好了之后,我可以再为弗利格尔先生写点什么别的东西。 等我写完时已是半夜时分,再没时间为弗利格尔先生写一篇循规蹈矩、像模像样的文章了。第二天上午,我别无选择,只好把我为自己而写的贝尔维尔晚餐的故事交了上去。两天后弗利格尔先生发还批改过的作文,他把别人的都发了,就是没有我的。我正准备着遵命一放学就去弗利格尔先生那儿挨训,却看见他从桌上拿起我的作文,敲了敲桌子让大家注意听。 "好了,孩子们,"他说。"我要给你们念一篇小品文。文章的题目是: 吃意大利细面条的艺术。"

完成Java面向对象程序设计实验课的心得体会范文

Java面向对象程序设计实验课的心得体会经过这几周对Java面向对象程序设计的学习,让我更加了解到Java学习的重要性。 在实验课上,我们完成多个实验,在这个阶段的学习中,我从认识到熟悉,而后到能够自主运用。通过对Java的了解,我发现它确实有很多方便之处,它集抽象性、封装性、继承性和多态性于一体,实现了代码重用和代码扩充,提高了软件开发的效率。对于我们这个专业来说学好Java语言是很重要的,所以在实验的过程中我都尽力理解java编程思想、掌握基本技巧,尽量学到最多的知识。 学习程序设计的基本目的就是培养描述实际问题的程序化解决方案的关键技能,Java面向对象程序设计是一门实践性比较强的课程,在实际中,我们必须把理论和实践结合起来。在实验中,我们理解理论课上的知识,然后运用到实际的操作中,我们必须在现有的理论的基础上,进行实践。多次实验后,也让我看到了现在学习的一个很大弱点:只听不练,永远不会熟练运用;空记技巧,忽略思想,会在多变的习题中十分无奈。 Java思想:Java是一门面向对向语言,他定义一切都是对象面向对象,就是面对现实; 现实中的一切都是对象,他们有分类,就产生了“类”; 他们有不同,类和类之间的不同,使用类来区分; 同一个类中不同的对象的区别,使用成员区分。

所以,面向对象的内部逻辑是分类。 面向对象编程思想就象数学上的一些概念,如:空间、群、环、域等 原始的编程思想就象古典数学,人们只在一个集合上探讨问题,没有系统的方法(即运算)定义,于是仁者见仁、智者见智,这样在一定程度上造成了理论的一种混乱局面,不利于科学的发展。于是近代数学向公理化发展,这是什么意思呢?就是说,人们除了在限定论域(即上面的集合,面向对象也有此概念)外,还在此论域上加进了一套通用的、公认的运算(方法);集合加上集合上定义的运算就构成了数学上的空间、群等,在计算机领域里,就变成为“类”。这种集合上定义了操作的东西利用起来就方便多了,这使得人们讨论问题时都在给定集合的运算能力上下工夫,即有通用性可事半功倍。 面向对象的编程思想就要想近世代数的分析思想,首先要确定“论域”,即工程所涉及到的所有的“对象”,然后要分类处理,把隶属同一类别的对象集合在一起(做成一个集合),定义他们之间的运算性质及可以进行的操作,这样就构建了一个类,当然以后用到这个类的对象时都要通过已经定义了的操作来完成各项功能,这就是常要求的类的“类的成员变量要通过共有函数来操作”。 我想真正的面向对象编程思想不应该是编程思想,应该是面向对象的分析方法才对! 我的理解: 1、将分析过程为抽象的过程:简言之:分成多个小问题(组成部分),

面向对象_补充案例

案例3-1 定义学生类 一、案例描述 1、考核知识点 编号:00103002 名称:类和对象 2、练习目标 掌握类定义的方式 掌握如何在类中定义成员变量和成员方法 3、需求分析 在面向对象的思想中最核心就是对象,在程序中创建对象的前提是需要定义一个类。为了让初学者掌握类的定义方式,本案例将设计一个表示学生的类,该类具有表示姓名的属性name和表示年龄的属性age,同时还具有表示说话行为的方法speak(),用于输出学生的姓名和年龄。 4、设计思路(实现原理) 1)使用class关键字定义一个表示学生类型的类,类名为Student。 2)在Student类中定义两个成员变量name和age,分别用来表示姓名和年龄。其中,name的数据类型为String,变量age的数据类型为int。 3)在Student类中定义一个表示说话行为的speak()方法,用于输出学生的姓名和年龄。二、案例实现 class Student{ String name; int age; void speak() { "我的名字是 "+name+",今年 "+age+"岁"); } } 三、案例总结 1、Java语言严格区分大小写,class和Class是不同的,在定义类时只能使用class关键字 2、在Student类中,成员变量name是String类型,String表示一个字符串,后面的章节会详细讲解 3、思考一下:自己定义一个手机(Phone)类,在类中定义品牌(brand)和价格(price)属性,定义打电话的call()方法,代码如下所示 public class Phone { String brand; double price; void call(){

新世纪高等院校英语专业写作教程第一册unit1-4课后答案

Unit 1 . The little boy was chicken-hearted. 2)That statesman is a respectable figure in the political arena. 3)We sat down by the oak tree ,enjoying the breeze coming from the lake. 4)We need to drink the milk before it sours. 5)The child had difficulty finding his way to school. 6)The young woman received a lot of flowers and gifts. 7)My father drew back the curtain a little lest I see him. 8)Our university can accommodate 4,000 students. 9)Social customs vary greatly from country to country. experienced 2)elapsed 3)attempting 4)with 5)take up 6)made 7)endeavor 8)true The state attorney said that the man would be prosecuted. 2)We suppose that a referee should be disinterested but not uninterested. 3)Tony can hit a ball farther than I can. 4)We must pursue this matter farther. 5)The principle behind our constitution are a principal reason for its astounding success. 6)All the band instruments except the tuba will be carried to the auditorium for the music contest. 7)The federal government comprises the legislative,judicial,and executive branches. 8)The whole region was struck by an economic disaster. 9)(correct) 10)He was awaked to the risk. Sixty hours is the amount of work time I contracted for. 2)The jury is expected to reach its decision very quickly. 3)Each of the candidates for the position has exceptionally high qualifications. 4)Every boy and girl in the sixth grade was at fault.. 7)He is one of the students who plan to attend the speech contest. 8)The jury are to be isolated in individual hotel rooms each night during the trial. 9)Sam sprawled in the chair and knocked over one of the lamps which were on display. 10)The symptoms of mercury poisoning vary with each individual case. 11)He believes that athletics improves school morale. 12)Up goes the starter”s gun,and each of the runners becomes tense. 13)Either The Moning Post or The City News is a reliable sourse of news. 14)The first thing that catches your eye is the headlines. 15)She is one of the women who have made this country what it is.

全新版大学英语综合教程1课后答案

Key to Exercises (unit 1) Vocabulary: I. 1). respectable 2) .agony 3). put down 4). sequence 4). rigid 5). hold back 6). distribute 7). off and on 8). vivid 9). associate 10). finally 11). turn in 12). tackle 2. 1) has been assigned to the newspaper’s Paris office 2) was so extraordinary that I didn’t know whether to believe him or not 3) a clear image of how she would look in twenty year s’ time 4) gave the command the soldiers opened fire 5) buying bikes we’ll keep turning them out 3.1) reputation/rigid / to inspire 2) and tedious / what’s more / out of date ideas 3) compose / career / avoid showing / hardly hold back II. 1). composed 2). severe 3) agony 4). extraordinary 5). recall 6). command 7). was violating 8). anticipate III. 1. at 2. for 3. of 4. with 5. as 6. about 7. to 8. in 9. from 10. on/upon Comprehensive Exercises (A) (1) hold back (2) tedious (3) scanned (4) recall (5) vivid (6) off and on (7) turn out/in (8) career (B) (1) last (2) surprise (3) pulled (4) blowing (5) dressed (6) scene (7) extraordinary (8)image (9)turn (11) excitement II. Translation 1 1) As it was a formal dinner party, I wore formal dress, as Mother told me to. 2) His girlfriend advised him to get rid of /get out of his bad habit of smoking before it took hold. 3) Anticipating that the demand for electricity will be high during the next few months, they have decided to increase its production. 4) It is said that Bill has been fired for continually violating the company’s

面向对象程序设计实验

实验一C++基础1.1 实验目的 1.了解并熟悉开发环境,学会调试程序; 2.熟悉C++中简单的标准输入输出函数的使用方法; 3.理解const修饰符的作用并学会应用; 4.理解内联函数的优缺点并学会其使用场合; 5.理解并学会函数重载; 6.理解并熟练掌握使用new和delete来分配内存; 7.理解并熟练掌握引用的使用方法。 1.2 实验内容 1.2.1 程序阅读 1.理解下面的程序并运行,然后回答问题。 #include int max_def(int x, int y) { return (x>y?x:y); } int max_def(int x, int y, int z) { int temp = 0; return (temp=(x>y?x:y))>z?temp:z; } double max_def(double x, double y) { return (x>y?x:y); } int main()

{ int x1 = 0; int x2 = 0; double d1 = 0.0; double d2 = 0.0; x1 = max_def(5,6); x2 = max_def(2,3,4); d1 = max_def(2.1,5.6); d2 = max_def(12.3,3.4,7.8);-----------------------------------------------------①cout<<"x1="<

写作教程课后答案上海外国语教育出版社

写作教程2 课后题答案提示:页码有部分错误,但答案内容正确。 P2 . PART1 Advantages : It is very convenient . You can make a call whenever and wherever you want to. It is especially helpful in an emergency . It saves time .You don't have to search for or await the turn for the public phone. You can always be reached when you are needed by others. In an information age ,it can help you to get the information you want in the quickest way. It may help you to grasp any chance to succeed. You can play games and surf the net through the phone. ....... Disadvantages : It is quite expensive Its radiation is harmful to health Answering calls in public places such as on a bus is embarrassing Making or answering calls while driving is

全新版大学英语综合教程(第二版)1课后题答案全集(可打印)

【一】全新版大学英语综合教程1课后 题 Unit 1 Growing Up Part II Language Focus Vocabulary Ⅰ.1. 1.Respectable 2.agony 3.put…down 4.sequence 5.hold back 6.distribute 7.off and on 8.vivid 9.associate 10.finally 1.turn in 2.tackle 2. 1.has been assigned to the newspaper’s Paris office. 2.was so extraordinary that I didn’t know whether to believe him or not. 3. a clear image of how she would look in twenty years’ time. 4.gave the command the soldiers opened fire. 5.buying bikes we’ll keep turning them out. 3. 1.reputation, rigid, to inspire 2.and tedious, What’s more, out of date ideas https://www.wendangku.net/doc/5b13679758.html,pose, career, avoid showing, hardly hold back Ⅱ. https://www.wendangku.net/doc/5b13679758.html,posed 2.severe 3.agony 4.extraordinary 5.recall https://www.wendangku.net/doc/5b13679758.html,mand 7.was violating 8.anticipate Ⅲ. 1.at 2.for 3.of 4.with 5.as 6.about 7.to 8.in, in

面向对象实验题及答案(全)

实验1 cin、cout及面向过程的编程实验2 引用与函数重载 实验3 类与对象 实验4 静态成员与对象参数 实验5 拷贝构造函数与内存分配 实验6 对象数组与子对象 实验7 含有数组成员的对象与深拷贝实验8 运算符重载(1) 实验9 运算符重载(2) 实验10 继承与派生 实验11 虚函数与类族 实验12 STL

实验1 cin 、cout 及面向过程的编程 1A :显示某个日期是星期几 (1) 输入、输出要求: 输入:3个正整数,依次为年、月、日,比如2049 10 1 输出:按类似“[2049-10-5] is Friday.”的形式输出 示例: (2) 处理方法 历史上的某一天是星期几?未来的某一天是星期几?关于这个问题,有很多计算公式,其中最著名的是蔡勒(Zeller)公式。即 7)%110)1(26244(-+? ?? ???++-??????+??????+=d m c c y y w 公式中的符号含义: w ——星期几 c ——年份的前两位 y ——年份的后两位 m ——月,3≤m ≤14,某年的1、2月视为上一年的13、14月,比如2003年1月1日要看作2002年的13月1日 d ——日 ??——代表取整,即只要整数部分 %——除法求余数 例如:对于2049年10月1日,计算过程如下: 5 7%547)%284051249(7)%1110)110(2620242044949(==+-++=-+??? ???++?-??????+??????+=w 即2049年10月1日是星期5。如果计算结果是负数,则加7。 1B :格式化输出实数 从键盘读取本金和年利率,求20年中每年末本息合计有多少钱。 输入:用空格分隔的两个数,都可以带小数点 输出:以“钱数(?年后)”的方式显示,以“2格、右对齐”的方式显示年,以“共10格、小数点后取2位、右对齐”的方式显示本息合计的钱数,见示例 示例:本金973.45元、年利率2%的显示结果如下

相关文档
相关文档 最新文档