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

上传人:孙刚 文档编号:1326595 上传时间:2019-10-17 格式:DOC 页数:9 大小:39KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试-74及答案解析.doc_第1页
第1页 / 共9页
【计算机类职业资格】二级JAVA机试-74及答案解析.doc_第2页
第2页 / 共9页
【计算机类职业资格】二级JAVA机试-74及答案解析.doc_第3页
第3页 / 共9页
【计算机类职业资格】二级JAVA机试-74及答案解析.doc_第4页
第4页 / 共9页
【计算机类职业资格】二级JAVA机试-74及答案解析.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、二级 JAVA 机试-74 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中,在下画线上填写代码,指定变量 b 为字节型,变量 f 为单精度实型,变量 1 为 64 位整型。public class java1public static void main(Stringargs)_b=49;_f=8.9f;_l=0xfedl;System.out.println(“b=“+b);System.out.println(“f=“+f);System.out.println(“l=“+1);(分数:30.00)_二、简单应用题(总题数:1

2、分数:40.00)2.本题是一个表格式的成绩单,其中包括“姓名”、“英语成绩”、“数学成绩”和“总成绩”,姓名和成绩都可以进行修改,单击按钮“计算每人总成绩”,则可以统计出每个人的总成绩并显示在总成绩栏中。import javax.swing.*;import java.awt.*;import java.awt.event.*;public class java2 extends JFrame implements ActionListenerJTable table;Object a;Object name=“姓名“,“英语成绩“,“数学成绩“,“总成绩“);JButton button

3、java2()setTitle(“java2“);a=new Object84;for(int i=0;i8;i+)for(int j=0;j4;j+)if(j!=0)aij=“;elseaij=“;button=new JButton(“计算每人总成绩“);table=_;button.addActionListener(this);getContentPane().add(new JScrollPane(table),BorderLayout.CENTER);getContentPane().add(button,BorderLayout.SOUTH);setSize(400,200);

4、setVisible(true);validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););public void actionPerformed(ActionEvent e)for(int i=0;i8;i+)double sum=0;boolean boo=true;for(int j=1;j=2;j+)trysum=sum+Double.parseDouble(_);catch(Exception ee)boo=false;table.r

5、epaint();if(boo=true)ai3=“+sum;table.repaint();public static void main(String args)java2 Win=new java2();(分数:40.00)_三、综合应用题(总题数:1,分数:30.00)3.本题中,通过菜单“Connect”显示一个对话框,单击“ok”按钮后,所填写的内容就会传回到主窗口并显示出来。import java.awt.*;import java.awt.event.*;import javax.swing.*;public class java3 extends JFrame impleme

6、nts ActionListenerpublic java3()setTitle(“java3“);setSize(300,300);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););JMenuBar mbar=new JMenuBar();setJMenuBar(bar);JMenu fileMenu=new JMenu(“File“);mbar.add(fileMenu);connectItem=new JMenuItem(“Connect“);conn

7、ectItem.addActionListener(this);fileMenu.add(connectItem);exitItem=new JMenuItem(“Exit“);exitItem.addActionListener(this);fileMenu.add(exitItem);public void actionPerformed(ActionEvent evt)Object source=evt.getSource();if(source=connectItem)ConnectInfo transfer=new ConnectInfo(“yourname“,“pw“);if(di

8、alog=null)dialog=new ConnectDialog(this);if(dialog.showDialog(transfer)String uname=transfer.username;String pwd=transfer.password;Container contentPane=getContentPane();contentPane.add(new JLabel(“username=“+uname+“,password=“+pwd),“South“);validate();else if(source=exitItem)System.exit(0);public s

9、tatic void main(Stringargs)JFrame f=new java3();f.show();private ConnectDialog dialog=null;private JMenuItem connectItem;private JMenuItem exitItem;class ConnectInfopublic String username;public String password;public Connectfnfo(String u,String p)username=u;password=p;class ConnectDialog extends JD

10、ialog implements ActionListenerpublic ConnectDialog()super(parent,“Connect“,true);Container contentPane=getContentPane();JPanel p1=new JPanel();p1.setLayout(new GridLayout(2,2);p1.add(new JLabel(“User name:“);p1.add(username=new JTextField(“);p1.add(new JLabel(“Password:“);p1.add(password=new JPassw

11、ordField(“);contentPane.add(“Center“,p1);Panel p2=new Panel();okButton=addButton(p2,“Ok“);cancelButton=addButton(p2,“Cancel“);contentPane.add(“South“,p2);setSize(240,120);JButton addButton(Container c,String name)JButton button=new JButton(name);button.addActionListener(this);c.add(button);return bu

12、tton;public void actionPerformed(ActionEvent evt)Object source=evt.getSource();if(source=okButton)ok=true;setVisible(false);else if(source=cancelButton)setVisible(false);public void showDialog(ConnectInfo transfer)username.setText(transfer.username);password.setText(transfer.password);ok=false;show(

13、);if(ok)transfer.username=username.getText();transfer.password=new String(password.getPassword();return ok;private JTextField username;private JPasswordField password;private boolean ok;private JButton okButton;private JButton cancelButton;(分数:30.00)_二级 JAVA 机试-74 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总

14、题数:1,分数:30.00)1.本题中,在下画线上填写代码,指定变量 b 为字节型,变量 f 为单精度实型,变量 1 为 64 位整型。public class java1public static void main(Stringargs)_b=49;_f=8.9f;_l=0xfedl;System.out.println(“b=“+b);System.out.println(“f=“+f);System.out.println(“l=“+1);(分数:30.00)_正确答案:(第 1 处:byte第 2 处:float第 3 处:long)解析:解析 本题考查的是数据类型。byte 为字节

15、型;float 为单精度实型;long 为长整型。二、简单应用题(总题数:1,分数:40.00)2.本题是一个表格式的成绩单,其中包括“姓名”、“英语成绩”、“数学成绩”和“总成绩”,姓名和成绩都可以进行修改,单击按钮“计算每人总成绩”,则可以统计出每个人的总成绩并显示在总成绩栏中。import javax.swing.*;import java.awt.*;import java.awt.event.*;public class java2 extends JFrame implements ActionListenerJTable table;Object a;Object name=“姓

16、名“,“英语成绩“,“数学成绩“,“总成绩“);JButton button;java2()setTitle(“java2“);a=new Object84;for(int i=0;i8;i+)for(int j=0;j4;j+)if(j!=0)aij=“;elseaij=“;button=new JButton(“计算每人总成绩“);table=_;button.addActionListener(this);getContentPane().add(new JScrollPane(table),BorderLayout.CENTER);getContentPane().add(button

17、BorderLayout.SOUTH);setSize(400,200);setVisible(true);validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););public void actionPerformed(ActionEvent e)for(int i=0;i8;i+)double sum=0;boolean boo=true;for(int j=1;j=2;j+)trysum=sum+Double.parseDouble(_

18、);catch(Exception ee)boo=false;table.repaint();if(boo=true)ai3=“+sum;table.repaint();public static void main(String args)java2 Win=new java2();(分数:40.00)_正确答案:(第 1 处:new JTable(a,name)第 2 处:aij.toString()解析:解析 第 1 处初始化表格变量;第 2 处取得表格中单元格内容并转换成 Double 型计算出总成绩。三、综合应用题(总题数:1,分数:30.00)3.本题中,通过菜单“Connect”

19、显示一个对话框,单击“ok”按钮后,所填写的内容就会传回到主窗口并显示出来。import java.awt.*;import java.awt.event.*;import javax.swing.*;public class java3 extends JFrame implements ActionListenerpublic java3()setTitle(“java3“);setSize(300,300);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0)

20、);JMenuBar mbar=new JMenuBar();setJMenuBar(bar);JMenu fileMenu=new JMenu(“File“);mbar.add(fileMenu);connectItem=new JMenuItem(“Connect“);connectItem.addActionListener(this);fileMenu.add(connectItem);exitItem=new JMenuItem(“Exit“);exitItem.addActionListener(this);fileMenu.add(exitItem);public void a

21、ctionPerformed(ActionEvent evt)Object source=evt.getSource();if(source=connectItem)ConnectInfo transfer=new ConnectInfo(“yourname“,“pw“);if(dialog=null)dialog=new ConnectDialog(this);if(dialog.showDialog(transfer)String uname=transfer.username;String pwd=transfer.password;Container contentPane=getCo

22、ntentPane();contentPane.add(new JLabel(“username=“+uname+“,password=“+pwd),“South“);validate();else if(source=exitItem)System.exit(0);public static void main(Stringargs)JFrame f=new java3();f.show();private ConnectDialog dialog=null;private JMenuItem connectItem;private JMenuItem exitItem;class Conn

23、ectInfopublic String username;public String password;public Connectfnfo(String u,String p)username=u;password=p;class ConnectDialog extends JDialog implements ActionListenerpublic ConnectDialog()super(parent,“Connect“,true);Container contentPane=getContentPane();JPanel p1=new JPanel();p1.setLayout(n

24、ew GridLayout(2,2);p1.add(new JLabel(“User name:“);p1.add(username=new JTextField(“);p1.add(new JLabel(“Password:“);p1.add(password=new JPasswordField(“);contentPane.add(“Center“,p1);Panel p2=new Panel();okButton=addButton(p2,“Ok“);cancelButton=addButton(p2,“Cancel“);contentPane.add(“South“,p2);setS

25、ize(240,120);JButton addButton(Container c,String name)JButton button=new JButton(name);button.addActionListener(this);c.add(button);return button;public void actionPerformed(ActionEvent evt)Object source=evt.getSource();if(source=okButton)ok=true;setVisible(false);else if(source=cancelButton)setVis

26、ible(false);public void showDialog(ConnectInfo transfer)username.setText(transfer.username);password.setText(transfer.password);ok=false;show();if(ok)transfer.username=username.getText();transfer.password=new String(password.getPassword();return ok;private JTextField username;private JPasswordField

27、password;private boolean ok;private JButton okButton;private JButton cancelButton;(分数:30.00)_正确答案:(第 1 处:setJMenuBar(mbar)第 2 处:public ConneetDialog(JFrame parent)第 3 处:public Boolean showDialog(ConnectInfotransfer)解析:解析 第 1 处参数错误,bar 未定义;第 2 处从下一行的 super(parent,“Connect“,true);可以看出,这里需要的参数为父窗体;第 3 处从下面的 return ok;等可以看出,这是一个有 Boolean 型返回值的函数,故类型应为 Boolean。

展开阅读全文
相关资源
猜你喜欢
  • KS V ISO 20858-2012 Maritime port facility security assessments and security plan development《船舶与海洋技术 航运港口设施安全评估和安全发展规划》.pdf KS V ISO 20858-2012 Maritime port facility security assessments and security plan development《船舶与海洋技术 航运港口设施安全评估和安全发展规划》.pdf
  • KS V ISO 21005-2012 Thermally toughened safety-glass panes for windows and side scuttles《船舶与海洋技术 海洋环境保护 撇油器的性能试验 第1部分 移动水域条件》.pdf KS V ISO 21005-2012 Thermally toughened safety-glass panes for windows and side scuttles《船舶与海洋技术 海洋环境保护 撇油器的性能试验 第1部分 移动水域条件》.pdf
  • KS V ISO 21072-1-2012 Ships and marine technology-Marine environment protection:Performance testing of oil skimmers-Part 1:Moving water conditions《船舶与海洋技术 海洋环境保护 石油回收船的性能试验 第2部分 静态.pdf KS V ISO 21072-1-2012 Ships and marine technology-Marine environment protection:Performance testing of oil skimmers-Part 1:Moving water conditions《船舶与海洋技术 海洋环境保护 石油回收船的性能试验 第2部分 静态.pdf
  • KS V ISO 21072-2-2012 Ships and marine technology-Marine environment protection:performance testing of oil skimmers-Part 2:Static water conditions《船舶与海洋技术 海洋环境保护 撇油器的性能试验 第3部分 高粘度油.pdf KS V ISO 21072-2-2012 Ships and marine technology-Marine environment protection:performance testing of oil skimmers-Part 2:Static water conditions《船舶与海洋技术 海洋环境保护 撇油器的性能试验 第3部分 高粘度油.pdf
  • KS V ISO 21072-3-2012 Ships and marine technology-Marine environment protection:performance testing of oil skimmers-Part 3:High viscosity oil 《造船 内河航行 日字环锚链的钢索起重机》.pdf KS V ISO 21072-3-2012 Ships and marine technology-Marine environment protection:performance testing of oil skimmers-Part 3:High viscosity oil 《造船 内河航行 日字环锚链的钢索起重机》.pdf
  • KS V ISO 22673-2011 Ships and marine technology-Launching appliances for free-fall lifeboats《船舶与海洋技术 自由降落式救生艇的降落装置》.pdf KS V ISO 22673-2011 Ships and marine technology-Launching appliances for free-fall lifeboats《船舶与海洋技术 自由降落式救生艇的降落装置》.pdf
  • KS V ISO 24408-2012 Position-indicating lights for life-saving appliances-Testing inspection and marking of production units《船舶与海洋技术 救生器具用定位指示灯 制造设备的试验、检查和标记》.pdf KS V ISO 24408-2012 Position-indicating lights for life-saving appliances-Testing inspection and marking of production units《船舶与海洋技术 救生器具用定位指示灯 制造设备的试验、检查和标记》.pdf
  • KS V ISO 27991-2011 Marine evacuation systems-Means of communication《船舶与海洋技术 海上疏散系统 通信方法》.pdf KS V ISO 27991-2011 Marine evacuation systems-Means of communication《船舶与海洋技术 海上疏散系统 通信方法》.pdf
  • KS V ISO 28000-2012 Specification for security management systems for the supply chain《供应链用安全管理系统的规范》.pdf KS V ISO 28000-2012 Specification for security management systems for the supply chain《供应链用安全管理系统的规范》.pdf
  • 相关搜索
    资源标签

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

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