【计算机类职业资格】计算机二级JAVA-148及答案解析.doc
《【计算机类职业资格】计算机二级JAVA-148及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】计算机二级JAVA-148及答案解析.doc(12页珍藏版)》请在麦多课文档分享上搜索。
1、计算机二级 JAVA-148 及答案解析(总分:69.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:-1.00)1.下列程序中,给出两个整数 2 和 3,分别求 2 除以 3 和 2 乘以 3 的结果,要求调用类 ex1_1 的方法method()来输出相应的结果,请将程序补充完整。程序运行结果如下: 0.6666666666666666 6 public class ex1_1 public static void main(Stringargs) int n1=2,n2=3; ex1_1 obj1_1=new ex1_1(); obj1_1. _; public void
2、 method(int x,int y) System.out.println(_); System.out.println(_); (分数:-1.00)_二、2简单应用题(总题数:1,分数:40.00)2.请完成以下程序,首先由一个类 Example2_3 实现 Serializable 接口,并有三个成员变量,分别为 int型、double 型和 String 型,可以用 toString 的方法显示这三个成员变量。在 main 方法中创建这个Example2_3 的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为 TheSerial.data 的文
3、件,并显示成员变量。最后从文件 TheSerial.data 中读出三个成员变量并显示出来。 注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; class TheSerial implements Serializable private int intValue; private double doubleValue; private String string; TheSerial() intValue = 123; doubleValue = 12.34; string = “Serialize Test“; public
4、 void setDouble(double d) doubleValue = d; public void setInt(int i) intValue = i; public void setString(String s) string = s; public String toString() return(“int=“+intValue+“double=“+doubleValue+“ string=“+string); public class Example2_3 public static void main(String argv) TheSerial e1 = new The
5、Serial(); TheSerial e2; try e1.setInt(Integer.parseInt(argv0); e1.setDouble(Double.parseDouble(argv1); e1.setStringargv2); catch(Exception e) e1.setString(e.getMessage); System.out.println(e1); try FileOutputStream oS = new FileOutputStream(“TheSerial.data“); ObjectOutputStream oIS = new ObjectOutpu
6、tStream(oS); _; catch(IOException ioException) System.out.println(ioException.getMessage(); try FileInputStream iS = new FileInputStream(“TheSerial. data“); ObjectInputStream oIS = new ObjectInputStream(iS); _ System.out.println(e2); catch(IOException ioException) System.out.println(ioException.getM
7、essage(); catch(ClassNotFoundException cnfException) System.out.println(cnfException.getMessage(); (分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.本题程序的功能是计算圆和三角形的面积。通过菜单“选择”可以分别进行圆和三角形面积的计算。单击菜单项“圆面积计算”,窗口中就会显示两个文本框和一个“确定”按钮,在第一个文本框中输入圆的半径,单击“确定”按钮后就可以在第二个文本框中显示圆的面积。单击菜单项“三角形面积计算”,窗口中就会显示 4 个文本框和一个“确定”按钮,在前三个
8、文本框中分别输入三角形三个边的长度,单击“确定”按钮后,如果三个边的长度不能组成三角形,结果文本框中会给出提示信息,否则显示三角形的面积;如果输入的值不是数值,则会给出提示信息。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; class circle extends Panel implements AetionListener double r,area; TextField radius = null,result = null; Button b = null; _; radius
9、 = new TextField(10); result = new TextField(10); b = new Button(“确定“); add (new Label (“输入半径“); add (radius); add(new Label(“面积是“); add(result); add(b); b.addActionListener (this); result,setEnabled (false); public void actionPerformed(ActionEvent e) try r = Double.parseDouble (radius.getText (); a
10、rea =Math.PI*r*r; result,setText (“+area); catch (Exception ee) radius.setText (“请输入数字字符“); class triangle extends Panel implements ActionListener double a = 0,b = 0,c = 0,area; TextField border a = new TextField(6) ; TextField border b = new TextField(6) ; TextField border c = new TextField(6) ; Re
11、sult = new TextField(24); Button button = new Button(“确定“); triangle () add(new Label(“输入三边的长度“); add (border_a); add (border_b); add (border_c); add(new Label(“面积是:“); add (result); add (button); button,addActionListener (this); result.setEnabled(false); public void actionPerformed(ActionEvent e) t
12、ry a = Double.parseDoubleborder_a.getText(); b = Double.parseDouble(border_b.getText(); c = Double.parseDouble(border_c.getText(); if(a+bca+cbc+ba) double p = (a+b+c)/2; area = Math.sqrt(p*(p-a)*(p-b)*(p-c); result.setText(“+ area); else result.setText (“您输入的数字不能形成三角形“); catch(Exception ee) result.s
13、etText (“请输入数字字符“); class Win _ implements ActionListener MenuBar bar = null; Menu menu = null; MenuItem item1,item2; circle circle; triangle trangle; Win() bar = new MenuBar(); menu = new Menu(“选择“); setSize(300,200); item1 = new MenuItem(“圆面积计算“); item2 = new MenuItem(“三角形面积计算“); menu.add(item1);
14、menu.add(item2); bar.add(menu); setMenuBar(bar); circle = new circle(); trangle = new triangle(); item1.addActionListener(this); item2.addActionListener(this); setVisible(true); public void actionPerformed(ActionEvent e) if (e.getSource() = item1) removeAll(); add(circle,“Center“); validate(); else
15、if(e.getSource() = item2) removeAll (); add (trangle,“Center“); validate (); public class advance public static void main (String args) Win win = new Win(); win.setTitle (“advance “); win.setBounds (100,100,700,300); win.setVisible (true); win.addWindowListener (_) public void windowClosing(WindowEv
16、ent e) System.exit (0); ); (分数:30.00)_计算机二级 JAVA-148 答案解析(总分:69.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:-1.00)1.下列程序中,给出两个整数 2 和 3,分别求 2 除以 3 和 2 乘以 3 的结果,要求调用类 ex1_1 的方法method()来输出相应的结果,请将程序补充完整。程序运行结果如下: 0.6666666666666666 6 public class ex1_1 public static void main(Stringargs) int n1=2,n2=3; ex1_1 obj1_
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA148 答案 解析 DOC
