【计算机类职业资格】二级JAVA机试-120及答案解析.doc
《【计算机类职业资格】二级JAVA机试-120及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级JAVA机试-120及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 JAVA 机试-120 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中数组 arr 中存储了学生的成绩,分别为 87,45,56,78,67,56,91,62,82,63,程序的功能是计算低于平均分的人数,并打印输出结果。请在程序空缺部分填写适当内容,使程序能正确运行。public class java1public static void main(Stringargs)int arr=56,91,78,67,56,87,45,62,82,63);int num=art.length;int i=0;int sumScor
2、e=0;int sumNum=0;double average;while(inum)sumScore=sumScore+arri;_;average=_;i=0;doif(arriaverage)sumNum+;i+;while(_);System.out.println(“average:“+average+“,belows average:“+sumNum);(分数:30.00)_二、简单应用题(总题数:1,分数:40.00)2.本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes”和“No”,单击对话框上的“Yes”和
3、“No”按钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。import java.awt.event.*;import java.awt.*;class MyDialog_implements ActionListenerstatic final int YES=1,NO=0;int message=-1;Button yes,no;MyDialog(Frame f,String s,boolean b)super(f,s,b);yes=new Button(“Yes“);yes.addActionListener(this);no=new Button(“No“);no.addAc
4、tionListener(this);setLayout(new FlowLayout();add(yes);add(no);setBounds(60,60,100,100);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)message=-1;setVisible(false););public void actionPerformed(ActionEvent e)if(e.getSource()=yes)message=YES;setVisible(false);else if(e.g
5、etSource()=no)message=NO;setVisible(false);public int getMessage()return message;class Dwindow extends Frame implements ActionListenerTextArea text;Button button;MyDialog dialog;Dwindow(String s)super(s);text=new TextArea(5,22);button=new Button(“打开对话框“);button.addActionListener(this);setLayout(new
6、FlowLayout();add(button);add(text);dialog=new MyDialog(this,“Dialog“,true);setBounds(60,60,300,300);setVisible(true);validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)(System.exit(0););public void actionPerformed(ActionEvent e)if(e.getSource()=button)_;if(dialog
7、.getMessage()=MyDialog.YES)text.append(“n 你单击了对话框的 yes 按钮“);else if(dialog.getMessage()=MyDialog.NO)text.append(“/n 你单击了对话框的 No 按钮“);public class java2public static void main(String args)(new Dwindow(“java2“);(分数:40.00)_三、综合应用题(总题数:1,分数:30.00)3.本题的功能是监听鼠标左右键的单击,以及面板中滚动条的添加。在窗口的画板中单击鼠标左键,在单击的位置绘制一个圆,
8、当绘制的圆大于画板的大小时,画板就添加滚动条,在画板中单击鼠标右键,则清除画板中的所有图形。import javax.swing.*;import javax.swing.event.MouseInputAdapter;import java.awt.*;import java.awt.event.*;import java.util.*;public class java3 extends JPanelprivate Dimension size;private Vector objects;private final Color colors=Color.red,Color.blue,Co
9、lor.green,Color.orange,Color.cyan,Color.magenta,Color.darkGray,Color.yellow;private final int color_n=colors.length;JPanel drawingArea;public java3()setOpaque(true);size=new Dimension(0,0);objects=new Vector();JLabel instructionsLeft=new JLabel(“单击鼠标左键画圆.“);JLabel instructionsRight=new JLabel(“单击鼠标右
10、键清空画板.“);JPanel instructionPanel=new JPanel(new GridLayout(0,1);instructionPanel.add(instructionsLeft);instructionPanel.add(instructionsRight);drawingArea=new JPanel()protected void paintComponent(Graphics g)super.paintComponent(g);Rectangle rect;for(int i=0;iobjects.size();i+)rect=(Rectangle)object
11、s.elementAt(i);g.setColor(colors(i%color_n);g.fillOval(rect.x,rect.y,rect.width,rect.height);drawingArea.setBackground(Color.white);drawingArea.addMouseListener(new MouseListener();JScrollPane scroller=new JScrollPane(drawingArea);scroller.setPreferredSize(new Dimension(200,200);setLayout(new Border
12、Layout();add(instructionPanel,BorderLayout.NORTH);add(scroller,BorderLayout.CENTER);class MyMouseListener extends mouseInputAdapterfinal int W=100;final int H=100;public void mouseReleased(MouseEvent e)boolean changed=false;if(SwingUtilities.isRightMouseButton(e)objects.removeAllElements();size.widt
13、h=0;size.height=0;changed=true;elseint x-e.getX()-W/2;int y=e.getY()-H/2;if(x0)x=0;if(Y0)y=0;Rectangle rect=new Rectangle(x,y,W,H);objects.addElement(rect);drawingArea.scrollRectToVisible(rect);int this_width=(x+W+2);if(this widthsize.width)size.width=this_width;changed=true;int this_height=(y+H+2);
14、if(this_heightsize.height)size.height=this_height;changed=true;if(changed)drawingArea.setPreferredSize(size);drawingArea.revalidate();drawingArea.paint();public static void main(String args)JFrame frame=new JFrame(“java3“);frame.addWindowListener(new WindowAdapter()public void windowClosing(WindowEv
15、ent e)System.exit(0););frame.setContentPane(new java3();frame.pack();frame.setVisible(true);(分数:30.00)_二级 JAVA 机试-120 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中数组 arr 中存储了学生的成绩,分别为 87,45,56,78,67,56,91,62,82,63,程序的功能是计算低于平均分的人数,并打印输出结果。请在程序空缺部分填写适当内容,使程序能正确运行。public class java1public sta
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA 机试 120 答案 解析 DOC
