JAVA6程序设计实践教程实验指导+课后答案.doc
第1章:1.6习题集:一、填空题1多态2java.exe 3jdb.exe 4标准字节码5Java 6独立于平台二、选择题1B2A3B4A5A6C7C8D9C第2章:实验指导:2.5.1第一处需要的代码:yourGuess>realNumber第二处需要的代码:yourGuess=input.nextInt();第三处需要的代码:yourGuess<realNumber第四处需要的代码:yourGuess=input.nextInt();2.5.2第一处需要的代码:iArrayi < iArrayj第二处需要的代码:iTemp = iArrayi; iArrayi = iArrayj; iArrayj = iTemp;2.5.3第一处需要的代码:continue lable;第二处需要的代码:System.out.print(" "+(i+j);2.5.4第一处需要的代码:System.out.print("t");第二处需要的代码:System.out.print(j + "*" + i + "=" + (i*j) + "t");2.6习题集:一、填空题1i=i+1 sum=sum+1 i<1002while do while for 394The symbol is an a.The symbol is a b.The symbol is c.The symbol is not a,b,or c.Switch is completed5sum=0 pos+二、选择题 1D2A3D4A 5D 6A 7B8B9C三、简答题 2、there is no this value 3Message four i is 1,2,3 i is 1,2,3 i is 1,2,3 i is 4第3章实验指导:3.10.1第一处需要的代码:balance+=saveAccount;第二处需要的代码:balance+=calculateInterst(Days);第三处需要的代码:ba.setMoney(save_value);ba.setInterstRate(interst_rate);第四处需要的代码:ba.accountInterst(365);3.10.2第一处需要的代码:minute=this.m_Minute;second=this.m_Second;第二处需要的代码:s=d.getMinutes()+":"+d.getSeconds()+":"+d.getTime();3.10.3第一处需要的代码:super(number,pass);balance=bal;第二处需要的代码:connect3.10.4第一处需要的代码:super(pass, motor);this.make=make;this.model=model;第二处需要的代码:am.run();3.11习题集:一、填空题1类2代码和数据3点4实例变量5Test te=new Test();6对象实例化7值、引用8the original is data is:-1now the data is:109I am parentI am childI am child二、选择题 1B 2A3C 4C5A 6A 7C 8A 9D 10C 11A 12C 13C三、简答题 6 A abstract和final修饰符不能同时使用B 未给出类型定义,final int MAX_NUMBER=10;C 常量不能修改D 静态方法值能访问静态变量,static int data。或者把方法标志为非静态方法,int getData()E 构造方法无返回值,把void去掉F 抽象类不能进行实例化,把abstract去掉G 子类不能继承父类的私有成员,应把Parent类中的mine属性的private修饰符去掉。H 父类对象不能与之类形式参数结合,可以颠倒过来。如下代码所示:class Parent int mine;class Child extends Parentint mine;class UseChildstatic int getMine(Parent p)return(p.mine);public static void main(String args) Child c=new Child();System.out.println(UseChild.getMine(c);第4章实验指导4.5.1第一处需要的代码:public void print()System.out.println("hello");yourGuess>realNumber第二处需要的代码:Hello h = new Hello(); h.print();4.5.2第一处需要的代码:public void stop() System.out.println("Network stop!");第二处需要的代码:public void start() System.out.println("Du du."); 第三处需要的代码:SoundCard sc=new SoundCard(); mb.usePCICard(sc);4.5.3第一处需要的代码:this.userAccount = acc; this.userPassword = pass;第二处需要的代码:public void show() System.out.println(resultMessage); 第三处需要的代码:user.connect();user.show();4.6习题集:一、填空题1javac d . Test.java 2package 3public4package com.my.test; public void inPut()System.out.println("n hi,keybroad has be input into then mainbroad!n"); public void inPut()System.out.println("n hi,netCardBroad has be input into then mainbroad!n"); publicvoid getMainMessage(Extendbroadable ext)ext.inPut();5Constants.MAX_COUNT6interface B extends Apublic void printB();二、选择题1C2D3B4C5B6C7C8B9D 10D 11D 12A三、简答(1) 1、接口是类似于类的结构,它只包含常量和抽象方法。在某些情况下,接口类似于抽象类,但是抽象类能够包含常量和抽象方法,还能够包含变量和具体方法。(2) 1、在接口中,数据可以是常量;而抽象类可以有数据字段。2、在接口中方法只有无实现的签名,而抽象类可以有具体的方法。3、因为定义在接口中的所有方法都是抽象方法,Java不要求将抽象修饰符放在4、接口中的方法签名中,但是在抽象类中要将抽象修饰符放在抽象方法之前。(3) 1、可以更好的组织类。2、减少类名的冲突问题,同一包中的类名不能重复,不同包中的类名可以重复;3、对包中的类起了一定的保护作用;(4) 1、直接引用指定的类,如import java.util.Vector;2、引用一个包中的多个类,如import java.awt.*。更确切的说,它并不是引用java.awt中的所有类,而只引用定义为public的类,并且只引用被代码引用的类,所以这种引用方法并不会降低程序的性能;3、*号代替类名,在不能代替包名,如import java.awt.*,只引用java.awt下的类,而不引用java.awt下的包;4、import java.awt.F*,这种使用方法是错误的;5、import语句在所有类定义之前,在package定义之后;6、import只告诉编译器及解释器哪里可以找到类、变量、方法的定义,而并没有将这些定义引入代码中;第5章实验指导:5.6.1第一处需要填写的代码:i<st.length()第二处需要填写的代码:st.indexOf("you")5.6.2第一处需要填写的代码:int i=0;i<a.length;i+;第二处需要填写的代码:ai=(char)(ai't');5.6.3第一处需要填写的代码:nowTime第二处需要填写的代码:matter1.format(nowTime)5.6.4第一处需要填写的代码:int i=0;i<days;i+第二处需要填写的代码:i%7=05.6习题集:一、填空题1equalsIgnoreCase 2Hello I like Java! 3char值4java.util.Date 5HELLO!6False 7a#a#a# 8xyz3459int len=str.length();c>='A'&&c<='Z'i+;10i=0;i<str.length();i+;int temp=str.charAt(i);sum+;二、选择题1B2A3A4B5D6A7B8D三、简答题1字符串的容量是:28用过setLength(200)后字符串的长度是:200使用了charAt(2):w2中国:The Money is: ¥30,215.00The Number is: 121.666673good and gbc4strawberry plum persimmon pear peach peach orange grape fig banana apple第6章实验指导6.4.1第一处需要的代码:number1 = Integer.parseInt( firstNumber); number2= Integer.parseInt( secondNumber);yourGuess>realNumber第二处需要的代码:NumberFormatException ex 6.4.2第一处需要的代码:catch(IOException e)System.out.println("catch "+e.toString(); 第二处需要的代码:catch(NumberFormatException e)System.out.println("catch "+e.toString(); 6.5习题集:一、填空题:1Welcome to javaThe finally clause is executed2Welcome to javaThe finally clause is executed3catch(NumberFormatException e)4仍然执行5ArithmeticException6IOException7数据转换错误异常8statement1,statement2二、选择题 1C2B3C4D5C6B7C第7章实验指导:7.6.1第一处需要填写的代码:panel.setVisible(true);第二处需要填写的代码:group.add(radioButton1); group.add(radioButton2);第三处需要填写的代码:mainPanel.add(panel);7.6.2第一处需要填写的代码:commentTabPane = new JTabbedPane();第二处需要填写的代码:tabAddComponent.add(nameLabel);第三处需要填写的代码:queryCom();7.6.3第一处需要填写的代码:System.exit(0);第二处需要填写的代码:new Counter(); 7.6.4第一处需要填写的代码:setVisible(true);第二处需要填写的代码:frame.getContentPane().add(new JTextArea();7.7习题集:一、填空题1btni=new JButton(strnamei); BorderLayout.EAST、BorderLayout.WEST、BorderLayout.SOUTH、BorderLayout.NORTH、BorderLayout.CENTER2frame.setContentPane(new CalculatorPanel().createPane();int y = 0; y < 4; y+、button = new JButton(lablesyx);3frame.getContentPane().add(new TreePanel().createComponent();node01.add(node0102); int i = 0; i < names.length; i+、panel.add(new JLabel(namesi);4jframe.setVisible(true); Container contentpane=jframe.getContentPane();text.append(s);5Container contentPanel = frame.getContentPane(); frame.setVisible(true); add(part2(); panel.setVisible(true);6Panel pan=new Panel();二、选择题1D2A3B4B5A6D7C第8章实验指导:8.6.1第一处需要的代码:contentPane.addMouseListener(this);contentPane.addMouseMotionListener(this);第二处需要的代码:g.drawLine(startx,starty,endx,endy);8.6.2第一处需要的代码:Container contentPane = f.getContentPane();第二处需要的代码:(e.getActionCommand().equals("按我有声音喔")8.6.3第一处需要的代码:treeModel.insertNodeInto(leafnode,node1,node1.getChildCount();第二处需要的代码:e.getSource()=tree8.6.4第一处需要的代码:b0.addActionListener(new Bt();第二处需要的代码:x=Double.parseDouble(tf1.getText().trim();8.7习题集:一、填空题1程序符号2授权事件模型3actionPerformed(ActionEvent e),itemStateChanged(ItemEvent e)4事件适配器5new WindowAdapter(),System.exit(0);二、选择题 1D 2C 3D 4B 5A 第9章参考答案:实验指导:9.4.1第一处需要填写的代码:g_2d.setStroke(bs);g_2d.setColor(Color.yellow);g_2d.draw(hourLine);第二处需要填写的代码:secondLine.setLine(120,120,(int)pointSXa,(int)pointSYa);9.4.2第一处需要填写的代码:signal.setRed(0);signal.setYellow(1);第二处需要填写的代码:g.setColor(Color.green);习题集:填空题:1Drawstring 2add(p1) 3toString(i)4public void paint(Graphics g)5int count=1;count<xpoint.length;count+6public void init()选择题:1A2B3B4B第10章实验指导:10.6.1第一处需要填写的代码:tempStr=bufReader.readLine();第二处需要填写的代码:s*=i;10.6.2第一处需要填写的代码:filePrex = null第二处需要填写的代码:int j = 0; j < children.length; j+10.6.3第一处需要填写的代码:inStream,outStream第二处需要填写的代码:copyBut,0,copyLen10.6.4第一处需要填写的代码:tempStr=inObj.readLine();习题集:一、填空题:1Hello!I like Java! 2110 110 110 110 1103InputStreamReaderBufferedReaderreadLine()4HelloWorld!5year%4=0&&year%100!=0|year%400=06String s="information to Appendn mon!n"二、选择题:1D2A3A4B5D6B7B8D第11章参考答案:实验指导:11.6.1第一处需要填写的代码:Class.forName(DBDRIVER) ;conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;第二处需要填写的代码:conn = getConnection();stmt = conn.createStatement();第三处需要填写的代码:stmt.executeUpdate("insert into t_test values('ew','dgf','dfg');"); stmt.executeUpdate("insert into t_test values('dg','df','fdg');"); stmt.executeUpdate("insert into t_test values('dfg','dfg','dfg');");stmt.executeUpdate("insert into t_test values('gdf','df','df');");第四处需要填写的代码:stmt.executeUpdate("delete from t_test;");11.6.2第一处需要填写的代码:pstmt=conn.prepareStatement("insert into t_grade values(?,?,?);");pstmt.setString(1,name);pstmt.setString(2,course);pstmt.setString(3,grade);pstmt.execute();第二处需要填写的代码:rs = stmt.executeQuery("select * from t_grade");while(rs.next()System.out.print("姓名:"+rs.getString("name");System.out.print(" 课程:"+rs.getString("course");System.out.println(" 成绩:"+rs.getString("grade");第三处需要填写的代码:try conn.close(); stmt.close(); rs.close(); catch(SQLException e)e.printStackTrace();11.6.3第一处需要填写的代码:conn = getConnection(); stmt = conn.createStatement(); stmt.executeUpdate("delete from t_grade where name = '"+name+"'");第二处需要填写的代码:pstmt = conn.prepareStatement("update t_grade set course = ?,grade=? where name = '"+name+"'"); pstmt.setString(1,course); pstmt.setString(2,grade); pstmt.execute();11.7习题集:一、填空题:1建立与数据库的连接、处理结果集2executeUpdate3CallableStatement4conn.createStatement();、rs.next();5conn.createStatement(ResultSet.Type_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE):、rs.updateRow();二、选择题:1B2A3B4B5C6A7A8C以下是大学体验英语综合教程2(第三版)课后翻译答案Unit11. 任何年满18岁的人都有资格投票。(be eligible to, vote)Answer:Anyone over the age of 18 is eligible to vote. 2. 每学期开学前,这些奖学金的申请表格就会由学校发给每一个学生。(apply for, scholarship)Answer:A form to apply for these scholarships is sent by the university to every student before the start of every semester. 3. 遵照医生的建议,我决定戒烟。(on the advice of)Answer:On the advice of my doctor, I decided to give up smoking. 4. 公园位于县城的正中央。(be located in)Answer:The park is located right in the center of town. 5. 这所大学提供了我们所需的所有材料和设备。(facilities) Answer:The university provides all the materials and facilities we desire.1. 他们花了多年的时间寻找内心的平静,但是收效甚微。(search for)Answer:They spent many years searching for peace of mind, but with little success. 2. 这种新药的成功研制已经使许多疾病的治疗发生了根本性的变革。(revolutionize)Answer:The successful development of the new drug has revolutionized the treatment of many diseases. 3. 由于这个国家的经济不景气,这家公司濒于破产。(on the edge of)Answer:The company is on the edge of bankruptcy due to the economic depression in the country. 4. 大学毕业后他成为了一名护士。他认为护士这一职业可能很有发展前途。(rewarding)Answer:He became a nurse after college. He thought nursing could be a very rewarding career. 5. 他像往常一样在文件上签了名。(just as) Answer:He signed his name on the paper just as he has always done it.Unit21. 警察们正忙着填写关于这场事故的各种表格。(fill out)Answer:The policemen are busy fi lling out forms about the accident. 2. 我想在还车之前把油箱加满。(fill up, fuel tank)Answer:I want to fi ll up the fuel tank before returning the car. 3. 如果你要投诉,最好遵循正确的程序。(follow the procedure)Answer:If you want to make a complaint, youd better follow the correct procedure. 4. 要不是约翰帮忙,我们绝不会这么快就完成实验。(without)Answer:We couldnt have fi nished the experiment so soon without Johns help. 5. 暴风雨之后,岸边的人们焦急地搜索湖面以期发现小船的踪迹。(scan for)Answer:After the storm, the people on the shore anxiously scanned the lake for any sign of the boat.1. 这个国家不大,但是在国际事务中它却发挥着重要作用。(play a role)Answer:This country is not big, but it plays an important role in international affairs. 2. 正是在我叔叔的帮助下,我得以克服困难,按时完成了任务。(it is . that)Answer:It was with the help of my uncle that I overcame the difficulty and completed the assignment in time. 3. 毕业时他决定留在北京,而他最好的朋友却选择了去西藏。(while)Answer:While he decided to stay in Beijing upon graduation, his best friend chose to go to Tibet. 4. 在这次校园英语演讲比赛中,我们班的玛丽获得了第三名。(come in)Answer:In this Campus English Speaking Contest, Mary from our class came in third. 5. 你应该知道学习弹钢琴需要有时间,有金钱,还要有毅力。(as well as) Answer:You should know that it takes time, money as well as perseverance to learn to play the piano.Unit31. 我发现量入为出地过日子越来越难了。(increasingly) Answer:I find it increasingly difficult to live within my income.2. 现代政治家们都试图以电视讲话来影响普通百姓。(reach out) Answer:Modern politicians try to reach out to ordinary people in their TV speeches.3. 应该帮助学生对人生采取积极的态度。(adopt) Answer:Pupils should be helped to adopt a positive attitude to life.4. 希望全班同学参加这些讨论。(participate in) Answer:Everyone in the class is expected to participate in these discussions.5. 如果你犯了罪就必须受到惩罚。(crime) Answer:If you commit a crime you must expect to be punished.1.儿子的死让老妇人变得麻木痴呆了。(numb)Answer:The old woman was numbed by her sons death.2.身处所有这些烦恼之中,他依然能保持乐观。(in the midst)Answer:In the midst of all troubles, he managed to remain cheerful.3. 虽有困难,他们还是设法坚持试验下去。(carry on) Answer:They managed to carry on their experiments in spite of the difficulties.4.我们必须淘汰不合格的申请人。(weed out) Answer:We have to weed out unqualified applicants.5. 医生要他减少抽烟。(cut down on) Answer:The doctor told him to cut down on smoking.Unit41.她在公共汽车站一直等到末班车进站。(come in)Answer:She waited at the bus stop until the last bus came in.2.如果我们能帮得上忙,尽管和我们联系。(contact)Answer:If there is any way we can be of assistance, please do not hesitate to contact us.3 .他需要多少船务人员才能使他的游艇航行?(crew, yacht)Answer:How many crew does he need to sail his yacht?4 .虽然她的新书没有上一本好,但是我还是喜欢它。(not quite as)Answer:I enjoyed her new book though its not quite as good as her last one.5 .我从未遇到过如此善良的人。(never before)Answer:Never before have I met such a kind person.1.公共汽车放慢速度并停下,让那位乘客上车。(slow down)Answer:The bus slowed down and stopped to allow the passenger to get on board.2.许多车子都驶过去了,可是没有一辆愿意让我们搭便车。(roll by)Answer:Many vehicles rolled by, but no one offered us a ride.3 .请勿践踏草地。(get off)Answer:Please get off the grass.4.他按妻子的吩咐,一下班就去了市场。(make ones way)Answer:He made his way to the marketplace right after work, as his wife had asked him to do.5 .值得庆幸的是,史蒂夫 (Steve) 从自行车上摔下来时没有摔断骨头。(luckily)Answer:Luckily, Steve didnt break any bones when he fell off his bike.Unit51. 我们得把感情放在一边,从专业的角度来对待这件事。(from a professional standpoint)Answer:We have to put aside our emotions and take it from a professional standpoint.2. 这部戏非常精彩,我很快就沉浸于激动人心的剧情之中。(lose oneself in)Answer:The play was so wonderful that I soon lost myself in the excitement of it.3 .她没有什么爱好除非你把看电视也算是一种爱好。(unless)Answer:She hasnt got any hobbies unless you call watching TV a hobby.4. 他说他是直接从市长本人那里得到这个信息的。(first-hand)Answer:He said that he had got the information first-hand from the Mayor himself.5 .既然你不能回答这个问题,我们最好问问别人。(since)Answer:Since you cant answer the question, perhaps wed better ask someone else.1. 由于公共汽