logo资料库

深圳职业技术学院——《面向对象程序设计(Java)》B 答案.doc

第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
资料共4页,全文预览结束
深 圳 职 业 技 术 学 院 电 信 学 院 软件工程系软件专业 XXXX-XXXX 学年第 X 学期期末考试( 必 修 ) 《面向对象程序设计(Java)》试卷 B【开卷】 —— 参考答案及评分标准 —— 一、填空题(每空 2 分,共 40 分) ⑴ x+"+"+y+"="+(x+y)或者”1+2=”+(x+y) ⑵ Runnale ⑶ 2 ⑷ A C ⑸ Synchnonized ⑹ 读取网络文件 http://edu.chinaren.com/index.shtml,并显示出来。 ⑺ (int)Math.random()*50+50 ⑻ 1 ⑼ a.length-1 或 5 ⑽ total*=a[i] 或 total=total*a[i] ⑾ C ⑿ 无连接 ⒀ throws IllegalAccessException ⒁ try ⒂ rtrme ⒃ r ⒄ FileReader ⒅ (c=fin.read())!= -1 ⒆ dbURL ⒇ sqlstr 二、编程题(共 60 分) 1 Person 类评分标准和参考答案:(15 分) 评分标准:类名、类声明正确 3 分 属性定义正确 3 分 构造方法 public Person(String s) 编写正确 2 分 构造方法 public Person(String s,char) 编写正确 2 分 构造方法 public Person(String s,char c,int i) 编写正确 2 分 方法 public String toString() 编写正确 3 分 参考答案: public class Person { String name; char sex; 第 1 页( 共 4页)
int age; public Person() {} public Person(String s) { name=s; } { } { public Person(String s,char c) this(s); sex=c; public Person(String s,char c,int i) this(s,c); age=i; } public String toString() { String s="姓名: "+name+" 性别:"+sex+" 年龄:"+age; return s; } } 2 Student 类 评分标准和参考答案:(15 分) 评分标准:类名、类声明正确 2 分 属性定义正确 2 分 方法 public Student(long k,String s,char c,int i,int i1,int i2,int i3) 编写正确 2 分 方法 public double aver() 编写正确 2 分 方法 public int max() 编写正确 2 分 方法 public int min() 编写正确 2 分 方法 public String toString() 编写正确 3 分 参考答案: public class Student extends Person { long number; int phi,eng,comp; public Student() {} public Student(long k,String s,char c,int i,int i1,int i2,int i3) { super(s,c,i); number=k; phi=i1; 第 2 页( 共 4页)
eng=i2; comp=i3; } public double aver() { return(phi+eng+comp)/3.0; } public int max() { int temp,max; temp=phi>eng?phi:eng; max=temp>comp?temp:comp; return max; } public int min() { int temp,min; temp=phi
程序窗体:3 分; 组件与添加:5 分; 事件监听器的添加:2 分; 实现 ActionLister 接口:2 分; 事件处理代码:5 分; 参考答案: import javax.swing.*;import java.awt.*;import java.awt.event.*; class Myframe extends JFrame implements ActionListener { JButton button;JTextArea text; Myframe() { setSize(200,400);setVisible(true); Container con=getContentPane(); con.setLayout(new FlowLayout()); button=new JButton("ok");text=new JTextArea(10,20); con.add(button);con.add(text); button.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);}}); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button) text.setText("I am a student,and you?"); } } public class MyGui { public static void main(String args[]) { Myframe fr=new Myframe();fr.pack(); } } 第 4 页( 共 4页)
分享到:
收藏