【计算机类职业资格】(A)二级JAVA笔试-5及答案解析.doc
《【计算机类职业资格】(A)二级JAVA笔试-5及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】(A)二级JAVA笔试-5及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、(A)二级 JAVA 笔试-5 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中,在下画线上填写代码,指定变量 b 为字节型,变量 f 为单精度实型,变量 l 为 64 位整型。public class java1public static void main(String args)_b=49;_f=8.9f;_1=0xfedl;System. out. println(“b=“+b);System. out. println(“f=“+f);System. out. println(“1=“+1);(分数:30.00)填空项 1
2、:_二、简单应用题(总题数:1,分数:30.00)2.本题是一个表格式的成绩单,其中包括“姓名”、“英语成绩”、“数学成绩”和“总成绩”,姓名和成绩都可以进行修改,单击按钮“计算每人总成绩”,则可以统计出每个人的总成绩并显示在总成绩栏中。import javax. swing. * ;import java. awt. * ;import java. awt. event. * ;public class java2 extends JFrame implements ActionListenerJTable table; Object a;Object name=“姓名“, “英语成绩“,
3、“数学成绩“, “总成绩“;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
4、, 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=l; j=2; j+)trysum=sum+Double. parse
5、Double(_);catch(Exception ee)boo=false;table. repaint();if(boo=true)ai3=“+sum;table. repaint();public static void main(String args)java2 Win=new java2();(分数:30.00)填空项 1:_三、综合应用题(总题数:1,分数:40.00)3.本题中,通过菜单“Connect”显示一个对话框,单击“ok”按钮后,所填写的内容就会传回到主窗口并显示出来。import java. awt. * ;import java. awt. event. * ;i
6、mport 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););JMenuBar mbar=new JMenuBar();setJMenuBar(bar);JMenu fileMenu=new JMenu(“Fi
7、le“);mbar. add(fileMenu);connectItem=new JMenuItem(“Connect“);connectltem. 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
8、=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=getContentPane();contentPane. add(new JLabel(“username=“+uname+“, passw
9、ord=“+pwd), “South“);validate();else if(source=exitItem)System. exit(0);public static void main(String args)JFrame f=new java3();f. show();private ConnectDialog dialog=null;private JMenuItem connectltem;private JMenuItem exitItem;class Connectlnfopublic String username;public String password;public
10、ConneetInfo(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(new GridLayout(2,2);p1. add(new JLabel(“User name:“);p1.
11、 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);setSize(240,120);JButton addButton(Container c, St
12、ring 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)setVisible(faIse);public void showDialog(Connec
13、tInfo 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 password;private boolean ok;priva
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA 笔试 答案 解析 DOC
