Java6程序设计实践教程实验指导课后答案_第1页
Java6程序设计实践教程实验指导课后答案_第2页
Java6程序设计实践教程实验指导课后答案_第3页
Java6程序设计实践教程实验指导课后答案_第4页
Java6程序设计实践教程实验指导课后答案_第5页
已阅读5页,还剩3页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第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 = iAr

2、rayj; 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 symb

3、ol 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);第三

4、处需要的代码: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.

5、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 未给出类

6、型定义,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 get

7、Mine(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()

8、 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); 第

9、三处需要的代码: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 mainbroa

10、d!n"); publicvoid getMainMessage(Extendbroadable ext)ext.inPut();5Constants.MAX_COUNT6interface B extends Apublic void printB();二、选择题1C2D3B4C5B6C7C8B9D 10D 11D 12A三、简答(1) 1、接口是类似于类的结构,它只包含常量和抽象方法。在某些情况下,接口类似于抽象类,但是抽象类能够包含常量和抽象方法,还能够包含变量和具体方法。(2) 1、在接口中,数据可以是常量;而抽象类可以有数据字段。2、在接口中方法只有无实现的签名,而抽象类可

11、以有具体的方法。3、因为定义在接口中的所有方法都是抽象方法,Java不要求将抽象修饰符放在4、接口中的方法签名中,但是在抽象类中要将抽象修饰符放在抽象方法之前。(3) 1、可以更好的组织类。2、减少类名的冲突问题,同一包中的类名不能重复,不同包中的类名可以重复;3、对包中的类起了一定的保护作用;(4) 1、直接引用指定的类,如import java.util.Vector;2、引用一个包中的多个类,如import java.awt.*。更确切的说,它并不是引用java.awt中的所有类,而只引用定义为public的类,并且只引用被代码引用的类,所以这种引用方法并不会降低程序的性能;3、*号代替

12、类名,在不能代替包名,如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+;第二处需要填

13、写的代码: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<='

14、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第一处需要的代

15、码: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 &q

16、uot;+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);第二处需要填写的代码

17、: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);第二处需要填写的代码:fr

18、ame.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.getCon

19、tentPane().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(

20、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.getActionComma

21、nd().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),itemStateChange

22、d(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);第二处需要填写

23、的代码: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 &

24、lt; 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

25、 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'

26、,'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('gd

27、f','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(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论