[计算机类试卷]国家二级(JAVA)机试模拟试卷17及答案与解析.doc

上传人:eveningprove235 文档编号:503547 上传时间:2018-11-29 格式:DOC 页数:4 大小:50KB
下载 相关 举报
[计算机类试卷]国家二级(JAVA)机试模拟试卷17及答案与解析.doc_第1页
第1页 / 共4页
[计算机类试卷]国家二级(JAVA)机试模拟试卷17及答案与解析.doc_第2页
第2页 / 共4页
[计算机类试卷]国家二级(JAVA)机试模拟试卷17及答案与解析.doc_第3页
第3页 / 共4页
[计算机类试卷]国家二级(JAVA)机试模拟试卷17及答案与解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级( JAVA)机试模拟试卷 17及答案与解析 一、基本操作题( 30分) 1 10位同学参加某次团队测试,要求每位同学都必须及格、同时团队平均分不少于 80分,整个团队才能够通过。每位同学的成绩可以通过随机数产生 (0 100)。请在程序的每条横线处填写一条语句,是程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 _ pulic class While public static void main(String args ) int fenshu=60; int sumfenshu=0; int i=1; while(fenshu

2、60) System.out.println(fenshu+ “ ) sumfenshu+=fenshu; i+; System.out.println(); if(_) System.out.println(“团队通过 “); else System. out. println ( “团队测试不通过 “); 二、简单应用题( 40分) 2 请完成下列 Java程序:生成一个窗口,包含一个长度为 100的横向滚动条,实现对这个滚动条状态的监视,计算出滚动条的位置在整个长度的百分比,并通过画布将该值输出在滚动条上方的区域中。 注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填

3、入适当的语句。 程序运行结果如下: import java.awt.*; import java.awt.event.*; public class ex19_2 extends Frame implements AdjustmentListener private Scrollbar sb; private msgWnd mw; private int val; public static void main(String arg) ex19_2 obj19_2=new ex19_2(); public ex19_2() setTitle(“ex19_2“); addWindowListen

4、er(WindowListener)new winListener(); mw = new msgWnd(); add(“Center“,mw); sb = new Scrollbar(Scrollbar. HORIZONTAL); sb.setVisibleAmount(10); sb.setBlockIncrement(6); sb.setUnitIncrement(5); sb.addAdjustmentListener(this); add(“South“,sb); pack(); show(); public void adjustmentValueChanged(Adjustmen

5、tEvent ae) val = ae.getValue(); _; class msgWnd extends Canvas msgWnd() setSize(450,20); public void paint(Graphics g) ( g.drawString(“ val=“ +_+“%“,10,15); class winListener extends WindowAdapter public void windowClosing(WindowEvent we) System.exit(0); 三、综合应用题( 30分) 3 下面是一个 Applet程序,其功能是根据公式: y=a*

6、sin(x)绘制正弦曲线。要求窗口中有一个文本区作为曲线峰值 a的输入,可以判断输入的数字是否符合要求,一个 ok按钮,点击则在画布中绘制曲线,以画布中的横坐标值作为 sin()的参数 x。请改正程序中的错误 (有下划线的语句 ),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下: import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.lang.Math.*; /* applet code=“ex18_3.class“ width=800 heig

7、ht=400 /applet */ public class ex18_3 extends Applet implements ActionListener Panel pane=new Panel(); drawWnd dw; Label 11 = new Label(“峰值 “); TextField tf1 = new TextField(15); Button btn = new Button(“OK“); private float a=0; public void init() pane.setLayout(new FlowLayout(FlowLayout.CENTER,25,5

8、); pane.add(11); pane.add(tf1); pane.add(btn); btn.addActionListener(this); add(“North“,pane); dw=new drawWnd(); add(“South“,dw); class drawWnd extends Canvas drawWnd() setSize(300,100); setBackground(Color. GRAY); public void paint(Graphics g) g.setColor(Color.GREEN); for(int i=0;igetSize().width-1

9、i+) int y=0; int y1=y+(int) (Math.sin(i)*a); int y2=y1+(int) (a*Math.sin(i+1); g.drawLine(i,y1,i+1,y2); public void actionPerformed(ActionEvent ae) try a=Integer.parseInt(tf1.getText(); dw.repaint(); catch(NumberFormatException nfe) tf1.setText(“error!“); ex18_3.html HTML HEAD TITLE ex18_3 /TITLE /

10、HEAD BODY applet code=“ex18_3.class“ width=800 height=400 /applet /BODY /HTML 国家二级( JAVA)机试模拟试卷 17答案与解析 一、基本操作题( 30分) 1 【正确答案】 import java math *; Math random()*100 (i=10)&(sumfenshu/10) =80) 【试题解析】 本题主要考查 while循环语句的用法。解答本题的关键 是熟练使用while循环语句。在本题中, import java math *;是用来导入 java math这个数学计算包, Math rand

11、om()*100语句是用来产生 100个随机数,if(i=10)&(sumfenshu/10) =80)语句的功能是用来判断团队的人数是否为10、平均分数是否大于等于 80。 二、简单应用题( 40分) 2 【正确答案】 mw repaint() val*100/sb getMaximum() 【试题解析】 本题主要考查 AWT基本构件滚动条的简单操 作和事件处理。解题关键是熟悉 ScrollBar构件的创建设置和相关事件的处理,会使用 Scrollbar的基本方法如用 getMaximum()得到滚动条的长度等。本题中,第 1个空,调用mpaint()方法,由于这里是在画布中实现绘图操作,因

12、此,应该使用画布的对象mw来调用此方法;第 2个空,计算滚动条当前位置占整体长度的百分比,用到了getMaximum()方法,注意由于是求百分比,因此需要再乘 100,否则结果为 0。 三、综合应用题( 30分) 3 【正确答案】 y=getSize() height/2 int y2=y+(int)(a*Math sin(i+1) a=Float parseFloat(tf1 getText() 【试题解析】 本题主要考查 Applet的图形绘制, Applet的生命周期以及其事件处理机制。解题关键是熟悉 Applet窗口中坐标的布局,会使用 TextField,Canvas, Button等构件,会使用内部类继承 Canvas类,实现在画布中绘制图像的方法,并通过在主程序中结合事件处理机制来调用该方法。本题中,第一处,由于画布中的纵坐标是从上向下从 0开始的,因此需 要有一个相对坐标原点,这里取画布的一半;第二处,计算下一点的坐标,应该是相对于坐标原点 y而言的坐标值,不应该是 y1;第三处, a为 float类型的变量,因此要用 Float类的类型转换方法。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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