【计算机类职业资格】二级JAVA机试60及答案解析.doc

上传人:testyield361 文档编号:1326669 上传时间:2019-10-17 格式:DOC 页数:4 大小:40.50KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试60及答案解析.doc_第1页
第1页 / 共4页
【计算机类职业资格】二级JAVA机试60及答案解析.doc_第2页
第2页 / 共4页
【计算机类职业资格】二级JAVA机试60及答案解析.doc_第3页
第3页 / 共4页
【计算机类职业资格】二级JAVA机试60及答案解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 JAVA机试 60及答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.在程序中,用户使用 JOptionPane输入一个二维数组的行数,程序随机生成每一行的列数,并对其赋值。最后显示这个二维数组。请填写横线处的内容。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import javax.swing.*; public class basic public static void main(String args) String sDimU=JOptionPane.showInputDialog

2、请输入数组的行数“); int iDimU=_(sDimU); int . numbers=new intiDimU ; for(int i=0; iiDimU; i+) int k=(int) (Math.random()*5+1); numbersi=_; for(int i=0; iiDimU; i+) for(int j=0;_; j+) numbersi j=(int) (Math.random()*l00); System.out.print(numbersi j+“ “); System.out.println (); System.exit(O) (分数:30.00)_二、

3、B2简单应用题/B(总题数:1,分数:40.00)2.请完成程序,首先由一个类 simple实现 Serializable接口,并有三个成员变量,分别为 int型、double型和 String型,可以用 toString的方法显示这三个成员变量。在 main方法中创建这个 simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件 TheSerial.data中读出三个成员变量并显示出来。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import j

4、ava.io.*; class TheSerial implements Serializable private int intvalue; private double doublevalue; private String string; The Serial () intvalue=123; doublevalue=12.34; string=“Serialize Test“; public void setDouble(double d) doublevalue=d; public void setInt(int i) intvalue=i; public void setStrin

5、g(String s) string=s; public String to String() return(“int=“+intvalue+“ double=“+doublevalue+“ string=“+string); public class simple public static void main(String args) The Serial e1=new TheSerial(); TheSerial e2; try e1.setInt(Integer.parseInt(args0); e1.setDouble(Double.parseDouble(args1); e1.se

6、tString(args2); catch(Exception e) e1.setString(e.getMessage(); System.out.println(e1); try FileOutputStream oS=new FileOutputStream(“TheSerial.data“); ObjectOutputStream oOS=new ObjectOutputStream(oS); _; catch(IOException ioException) System.out.println (ioException.getMessage (); try FileInputStr

7、eam iS=new FileInputStream(“TheSerial.data“); ObjectInputStream oIS=new ObjectInputStream(iS); _; System.out.println(e2); catch(IOException ioException) System.out.println(ioException.getMessage(); catch(ClassNotFoundException cnfException) System.out.println(cnfException.getMessage(); (分数:40.00)_三、

8、B3综合应用题/B(总题数:1,分数:30.00)3.本程序的目的是在屏幕上显示当前目录下的文件信息。文件信息通过表格 JTable的实例显示。请更正题中带下划线的部分,使程序能输出正确的结果。 注意:不改变程序的结构,不得增行或删行。 import java.awt.*; import javax.swing.*; import java.util.Date; import javax.swing.table.*; import java.applet.*; import java.io.*; public class advance Uextends JApplet, JFrame/U p

9、ublic void init() FileModel fm=new FileModel(); JTable jt=new UJTable()/U; jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); JScrollPane jsp=new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); public static void main(String args) advance ft=new advanc

10、e(); ft.init(); JFrame f=new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(ft.getContentPane(); f.setSize(300,400); f.show(); class FileModel extends AbstractTableModel String columnName=new String “文件名“,“大小“,“最后修改时间“ ; Object data; public FileModel() this(“.“);

11、public FileModel(String dir) File file=new File(dir); String files=file.list(); data=new Objectfiles.length columnName.length; for(int i=0; ifiles.length; i+) File tmp=new File(filesi); datai 0=tmp.getName(); datai 1=new Long(tmp.length(); datai 2=new Date(tmp.lastModified(); public int UgetColumnNu

12、mber/U() return columnName.length; public int getRowCount() return data.length; public String getColumnName(int col) return columnNamecol; public Object getValueAt(int row, int col) return datarow col; public Class getColumnClass(int c) return getValueAt(0,c).getClass(); (分数:30.00)_二级 JAVA机试 60答案解析(

13、总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.在程序中,用户使用 JOptionPane输入一个二维数组的行数,程序随机生成每一行的列数,并对其赋值。最后显示这个二维数组。请填写横线处的内容。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import javax.swing.*; public class basic public static void main(String args) String sDimU=JOptionPane.showInputDialog(“请输入数组的行数“); int

14、iDimU=_(sDimU); int . numbers=new intiDimU ; for(int i=0; iiDimU; i+) int k=(int) (Math.random()*5+1); numbersi=_; for(int i=0; iiDimU; i+) for(int j=0;_; j+) numbersi j=(int) (Math.random()*l00); System.out.print(numbersi j+“ “); System.out.println (); System.exit(O) (分数:30.00)_正确答案:()解析:Integer.pa

15、rseInt new intk jnumberi.length 讲解 本题考查知识点:基本数据类型包装类的使用,数组的使用。解题思路:首先, JOptionPane 显示了一个可以输入数据的对话框,用户通过该对话框输入对话框的行数。第一个循环是对每一行分配存储空间,第二个循环是对已经分配好空间的二维数据进行赋值,并在赋值的过程中将数组显示出来。第 1个空考查字符串和数值之间的相互转换。每一种基本数据类型的包装类都有各自的方法将字符串转换为相应的基本数据类型,转换为 int型的方法是Integer.parseInt()。第 2个空考查多维数组的基本概念,多维数组的高维标识低维的名字,但是低维必须

16、分配自己的存储空间。因此,此处需要用 new关键字对每一行动态分配列空间。第 3个空,由于多维数组的高维标识低维的名字,所以高维可以直接用来表示低维部分,使用方法跟普通数组一样。如本题中number0就表示一个用 number0命名的一维数组。所以此处应该填写 jnumberi.length。二、B2简单应用题/B(总题数:1,分数:40.00)2.请完成程序,首先由一个类 simple实现 Serializable接口,并有三个成员变量,分别为 int型、double型和 String型,可以用 toString的方法显示这三个成员变量。在 main方法中创建这个 simple的持久对象,根

17、据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件 TheSerial.data中读出三个成员变量并显示出来。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; class TheSerial implements Serializable private int intvalue; private double doublevalue; private String string; The Serial () intvalue=123;

18、doublevalue=12.34; string=“Serialize Test“; public void setDouble(double d) doublevalue=d; public void setInt(int i) intvalue=i; public void setString(String s) string=s; public String to String() return(“int=“+intvalue+“ double=“+doublevalue+“ string=“+string); public class simple public static voi

19、d main(String args) The Serial e1=new TheSerial(); TheSerial e2; try e1.setInt(Integer.parseInt(args0); e1.setDouble(Double.parseDouble(args1); e1.setString(args2); catch(Exception e) e1.setString(e.getMessage(); System.out.println(e1); try FileOutputStream oS=new FileOutputStream(“TheSerial.data“);

20、 ObjectOutputStream oOS=new ObjectOutputStream(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

21、) System.out.println(ioException.getMessage(); catch(ClassNotFoundException cnfException) System.out.println(cnfException.getMessage(); (分数:40.00)_正确答案:()解析:oOs.writeObject(e1) e2=(TheSerial)oIS.readObject() 讲解 本题考查知识点:串行化要领和目的、串行化方法、基于文本的应用。解题思路:本题主要考查串行化相关的方法和实现。解题中首先要掌握串行化的基本过程和反串行化的过程。串行化过程首先要创建

22、一个 FileOutputStream,通过该类的实例对文件进行访问,然后创建一个 ObjectOutputStream对象,通过 writeObject()方法来实现对象的序列化。第 1个空就是使用 writeObject()实现序列化。反序列化过程中用 FileInputStream对象建立读取文件的连接,并使用该对象创建一个 ObjectInputSream实例的 readObject()方法就可以实现对象的反序列化。第 2个空就是使用 readObject()实现反序列化。三、B3综合应用题/B(总题数:1,分数:30.00)3.本程序的目的是在屏幕上显示当前目录下的文件信息。文件信息

23、通过表格 JTable的实例显示。请更正题中带下划线的部分,使程序能输出正确的结果。 注意:不改变程序的结构,不得增行或删行。 import java.awt.*; import javax.swing.*; import java.util.Date; import javax.swing.table.*; import java.applet.*; import java.io.*; public class advance Uextends JApplet, JFrame/U public void init() FileModel fm=new FileModel(); JTable

24、jt=new UJTable()/U; jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); JScrollPane jsp=new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); public static void main(String args) advance ft=new advance(); ft.init(); JFrame f=new JFrame(); f.setDefaultClos

25、eOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(ft.getContentPane(); f.setSize(300,400); f.show(); class FileModel extends AbstractTableModel String columnName=new String “文件名“,“大小“,“最后修改时间“ ; Object data; public FileModel() this(“.“); public FileModel(String dir) File file=new File(dir); S

26、tring files=file.list(); data=new Objectfiles.length columnName.length; for(int i=0; ifiles.length; i+) File tmp=new File(filesi); datai 0=tmp.getName(); datai 1=new Long(tmp.length(); datai 2=new Date(tmp.lastModified(); public int UgetColumnNumber/U() return columnName.length; public int getRowCou

27、nt() return data.length; public String getColumnName(int col) return columnNamecol; public Object getValueAt(int row, int col) return datarow col; public Class getColumnClass(int c) return getValueAt(0,c).getClass(); (分数:30.00)_正确答案:()解析:extends JFrame JTable(fm) getColumnCount 讲解 本题考查知识点:JTable 构件的

28、使用、小程序的安全机制。解题思路:FileModel 定义了一个 JTable的模型,在这个模型中,File file=new File(dir)语句获得当前目录下的文件信息,然后将这些文件信息存储在模型的 data变量中。Applet 的沙箱模型规定,未授权的小应用程序不能访问本地资源,当然也就不能读、写本地计算机的文件系统。本程序需要获得当前目录的信息,因此本题程序只能作为应用程序运行,所以第 1处下划线应该去掉JApplet。JTable 的主要功能是将数据以二维表格的方式显示出来。本题采用的是 MVC模式,FileModel实现了表格的模型。第 2条下划线处使用 JTable的构造方法将模型赋予表格“it”。 AbstractTableModel所有的抽象方法都需要实现。第 3条下划线处的方法在功能上与抽象方法 getColumnCount()相同,但是并没有实现该抽象方法。因此需要更正。

展开阅读全文
相关资源
猜你喜欢
  • NF F55-623-1995 Railway fixed equipment Halogen free cables for remote controls and teletransmissions used in underground railway networks 《铁路固定设备 地铁内网络内遥控装置和远程传送用无卤化物电缆》.pdf NF F55-623-1995 Railway fixed equipment Halogen free cables for remote controls and teletransmissions used in underground railway networks 《铁路固定设备 地铁内网络内遥控装置和远程传送用无卤化物电缆》.pdf
  • NF F55-624-1991 Fixed railway equipment Halogen free cables for telecommunications for local customs used in underground railway netsworks 《铁路固定设备 地下铁路网路中局部用户通信用无卤素电缆》.pdf NF F55-624-1991 Fixed railway equipment Halogen free cables for telecommunications for local customs used in underground railway netsworks 《铁路固定设备 地下铁路网路中局部用户通信用无卤素电缆》.pdf
  • NF F55-625-1993 Railway fixed equipments Halogen free low voltage power cords and cables used to underground railway network fixed equipment cables for electric traction or lightin.pdf NF F55-625-1993 Railway fixed equipments Halogen free low voltage power cords and cables used to underground railway network fixed equipment cables for electric traction or lightin.pdf
  • NF F55-633-1995 Railway fixed equipment Telecommand and teletransmission cables used to urban railway network 《铁路固定设备 城市铁路网用远程控制和传输电缆》.pdf NF F55-633-1995 Railway fixed equipment Telecommand and teletransmission cables used to urban railway network 《铁路固定设备 城市铁路网用远程控制和传输电缆》.pdf
  • NF F55-641-1992 Product specification for optical fibre cables used in underground railways networks 《地铁网络用光缆的规范》.pdf NF F55-641-1992 Product specification for optical fibre cables used in underground railways networks 《地铁网络用光缆的规范》.pdf
  • NF F55-642-1992 Product specification for optical fibre used in railways networks for telecommunication on average and long distance 《平均长度和长距离通信铁路网用光纤的产品规范》.pdf NF F55-642-1992 Product specification for optical fibre used in railways networks for telecommunication on average and long distance 《平均长度和长距离通信铁路网用光纤的产品规范》.pdf
  • NF F55-646-1994 Railway fixed equipment Electric conductors used for the device and rail connnection in the track circuits fitting the electrified lines 《铁路固定设备 铁路上轨端电气连接和装置用导电体》.pdf NF F55-646-1994 Railway fixed equipment Electric conductors used for the device and rail connnection in the track circuits fitting the electrified lines 《铁路固定设备 铁路上轨端电气连接和装置用导电体》.pdf
  • NF F55-675-1994 Railway fixed equipment Power cables with synthetic insulation with rated voltage uo U (um)  3 2 3 2 (3 6) kv used for supplying signalling installations 《铁路固定设备 信号.pdf NF F55-675-1994 Railway fixed equipment Power cables with synthetic insulation with rated voltage uo U (um) 3 2 3 2 (3 6) kv used for supplying signalling installations 《铁路固定设备 信号.pdf
  • NF F55-681-1996 RAILWAY FIXED EQUIPMENT ANNEALING COPPER BARE CONDUCTORS 《铁路固定设备 退火铜裸导线》.pdf NF F55-681-1996 RAILWAY FIXED EQUIPMENT ANNEALING COPPER BARE CONDUCTORS 《铁路固定设备 退火铜裸导线》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1