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

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

1、二级 JAVA 机试-48 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题的功能是计算二维数组各个元素的和。程序中定义了二维数组 arr,arr 有 3 行 4 列共 12 个元素,程序中采用 for 循环语句的嵌套来计算数组中各个元素的和,并将结果保存在 sum 变量中,最后打印输出结果。public class java1public static void main(Stringargs)int arr=1,2,3,4,5,6,7,8,(9,10,11,12;int sum=0;int i=0,j=0;for(i=0;_)fo

2、r(_)_;System.out.println(“sum=“+sum);(分数:30.00)_二、简单应用题(总题数:1,分数:40.00)2.本题是设计一个窗体,窗口的背景色为系统桌面的颜色,在窗口中分别画了空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画了白色粗体的“Java 二级考试!”字符串。Import java.awt.*;Import javax.swing.*;Public class java2Public static void main(stringargs)Fillframe frame=new fillframe();Frame.setdefaultclo

3、seoperation(jframe.exit_on_close);Frame.show();Class fillframe extends jframePublic fillframe()Settitle(“simple“);Setsize(width,height);Fillpanel panel=new fillpanel();Panel.setbackground(systemcolor.desktop);Container contentpane=getcontentpane();Contentpane.add(panel);Public static final int width

4、=400;Public static final int width=250;Class fillpanel extends jpanelPublic void paintcomponent(graphics g)_;g.setcolor(new color(10,10,10);g.drawrect(10,10,100,30);g.setcolor(new color(100,100,100);g.drawroundrect(150,10,100,30,15,15);g.setcolor(new color(150,150,150);g.drawoval(280,10,80,30);g.set

5、color(new color(10,10,10);g.fillrect(10,110,100,30);g.setcolor(new color(100,100,100);g.drawroundrect(150,110,100,30,15,15);g.setcolor(new color(150,150,150);g.filloval(280,110,80,30);g.setcolor(color.white),font f=new font(“宋体“,_,20);g.setfont(f);g.drawstring(“java 二级考试!“,150,200);(分数:40.00)_三、综合应用

6、题(总题数:1,分数:30.00)3.本题的功能是监听鼠标的操作。鼠标置于窗口中单击时(左键或右键),在单击的地方会画一个小矩形,如果将鼠标置于小矩形上,则鼠标光标状态改为小十字,按下鼠标左键可拖曳,双击鼠标左键(或右键)时,小矩形消失。import java.awt.*;import java.awt.event.*;import java.util.*;import java.awt.geom.*;import javax.swing.*;public class java3public static void main(Stringargs)MouseFrame frame=new Mo

7、useFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();class MouseFrame extends JFramepublic MouseFrame()setTitle(“java3“);setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);MousePanel panel=new MousePanel();Container contentPane=geeContentPane();contentPane.add(panel);public static final i

8、nt DEFAULT_WIDTH=300;public static final int DEFAULT_HEIGHT=200;class MousePanel extends JPanelpublic MousePanel()squares=new ArrayList();current=null;addMouseListener(new MouseHandler();addMouseMotionListener(new MouseMorionHandler();public void paintComponent(Graphics g)super.paintComponent(g);Gra

9、phics2D g2=(Graphics2D)g;for(int i=0;isquares.size();i+)g2.draw(Rectangle2D)squares.get(i);public void find(Point2D p)for(int i=0;isquares.size();i+)Rectangle2D r=(Rectangle2D)squares.get(i);if(r.contains(p)return r;return null;public void add(Point2D p)double x=p.getX();double y=p.getY();current=ne

10、w Rectangle2D.Double(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH),squares.add(current);repaint();public void remove(Rectangle2D s)if(s=null)return;if(s=current)current=null;squares.remove(s);repaint();private static final int SIDELENGTH=10;private ArrayList squares;private Rectangle2D curren

11、t;private class MouseHandler extends MouseActionListenerpublic void mousePressed(MouseEvent event)current=find(event.getPoint();if(current=null)add(event.getPoint();public void mouseClicked(MouseEvent event)current=find(event.getPoint();if(current!=null private class MouseMotionHandler implements Mo

12、useMotionListenerpublic void mouseMoved(MouseEvent event)if(find(event.getPoint)=null)setCursor(Cursor.getDefaultCursor();elsesetCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);public void mouseDragged(MouseEvent event)if(current!=null)int x=event.getX();int y=event.getY();current.setFram

13、e(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH);repaint();(分数:30.00)_二级 JAVA 机试-48 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题的功能是计算二维数组各个元素的和。程序中定义了二维数组 arr,arr 有 3 行 4 列共 12 个元素,程序中采用 for 循环语句的嵌套来计算数组中各个元素的和,并将结果保存在 sum 变量中,最后打印输出结果。public class java1public static void main(String

14、args)int arr=1,2,3,4,5,6,7,8,(9,10,11,12;int sum=0;int i=0,j=0;for(i=0;_)for(_)_;System.out.println(“sum=“+sum);(分数:30.00)_正确答案:(第 1 处:i3;i+或 i=2;i+第 2 处:j=0;j4;j+或 j=0;j=3;j+第 3 处:sum=sum+arrij)解析:解析 第 1 处、第 2 处是由该数组是 3 行 4 列的数组而得出的遍历数组的循环条件;第 3 处是将数组元素累加并将最终累加结果赋给 sum。二、简单应用题(总题数:1,分数:40.00)2.本题是设

15、计一个窗体,窗口的背景色为系统桌面的颜色,在窗口中分别画了空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画了白色粗体的“Java 二级考试!”字符串。Import java.awt.*;Import javax.swing.*;Public class java2Public static void main(stringargs)Fillframe frame=new fillframe();Frame.setdefaultcloseoperation(jframe.exit_on_close);Frame.show();Class fillframe extends jframe

16、Public fillframe()Settitle(“simple“);Setsize(width,height);Fillpanel panel=new fillpanel();Panel.setbackground(systemcolor.desktop);Container contentpane=getcontentpane();Contentpane.add(panel);Public static final int width=400;Public static final int width=250;Class fillpanel extends jpanelPublic v

17、oid paintcomponent(graphics g)_;g.setcolor(new color(10,10,10);g.drawrect(10,10,100,30);g.setcolor(new color(100,100,100);g.drawroundrect(150,10,100,30,15,15);g.setcolor(new color(150,150,150);g.drawoval(280,10,80,30);g.setcolor(new color(10,10,10);g.fillrect(10,110,100,30);g.setcolor(new color(100,

18、100,100);g.drawroundrect(150,110,100,30,15,15);g.setcolor(new color(150,150,150);g.filloval(280,110,80,30);g.setcolor(color.white),font f=new font(“宋体“,_,20);g.setfont(f);g.drawstring(“java 二级考试!“,150,200);(分数:40.00)_正确答案:(第 1 处:super.paintComponent(g);第 2 处:Font.BOLD)解析:解析 第 1 处是通过 super 语句调用父类的构造方

19、法 paintComponent(g)。第 2 处是通过字体对象的构造函数,设置“Java 二级考试!”格式,题目要求是粗体,所以大 Font.BOLD。三、综合应用题(总题数:1,分数:30.00)3.本题的功能是监听鼠标的操作。鼠标置于窗口中单击时(左键或右键),在单击的地方会画一个小矩形,如果将鼠标置于小矩形上,则鼠标光标状态改为小十字,按下鼠标左键可拖曳,双击鼠标左键(或右键)时,小矩形消失。import java.awt.*;import java.awt.event.*;import java.util.*;import java.awt.geom.*;import javax.s

20、wing.*;public class java3public static void main(Stringargs)MouseFrame frame=new MouseFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();class MouseFrame extends JFramepublic MouseFrame()setTitle(“java3“);setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);MousePanel panel=new MousePanel();

21、Container contentPane=geeContentPane();contentPane.add(panel);public static final int DEFAULT_WIDTH=300;public static final int DEFAULT_HEIGHT=200;class MousePanel extends JPanelpublic MousePanel()squares=new ArrayList();current=null;addMouseListener(new MouseHandler();addMouseMotionListener(new Mou

22、seMorionHandler();public void paintComponent(Graphics g)super.paintComponent(g);Graphics2D g2=(Graphics2D)g;for(int i=0;isquares.size();i+)g2.draw(Rectangle2D)squares.get(i);public void find(Point2D p)for(int i=0;isquares.size();i+)Rectangle2D r=(Rectangle2D)squares.get(i);if(r.contains(p)return r;r

23、eturn null;public void add(Point2D p)double x=p.getX();double y=p.getY();current=new Rectangle2D.Double(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH),squares.add(current);repaint();public void remove(Rectangle2D s)if(s=null)return;if(s=current)current=null;squares.remove(s);repaint();private

24、static final int SIDELENGTH=10;private ArrayList squares;private Rectangle2D current;private class MouseHandler extends MouseActionListenerpublic void mousePressed(MouseEvent event)current=find(event.getPoint();if(current=null)add(event.getPoint();public void mouseClicked(MouseEvent event)current=fi

25、nd(event.getPoint();if(current!=null private class MouseMotionHandler implements MouseMotionListenerpublic void mouseMoved(MouseEvent event)if(find(event.getPoint)=null)setCursor(Cursor.getDefaultCursor();elsesetCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);public void mouseDragged(Mous

26、eEvent event)if(current!=null)int x=event.getX();int y=event.getY();current.setFrame(x-SIDELENGTH/2,y-SIDELENGTH/2,SIDELENGTH,SIDELENGTH);repaint();(分数:30.00)_正确答案:(第 1 处:public Rectangle2D find(Point2D p)第 2 处:private class MouseHandler extends MouseAdapter第 3 处:find(event.getPoint()=null)解析:解析 第 1 处定义一个返回类型为 Rectangle2D 的 find 函数且有一个 Point2D 型的形参;第 2 处定义了继承鼠标适配器 MouseAdapt 的 MouseHandler;第 3 处判断 find 函数的返回值是否为空。

展开阅读全文
相关资源
猜你喜欢
  • DIN 76-1-2016 Thread run-outs and thread undercuts - Part 1 For ISO metric threads in accordance with DIN 13-1《符合DIN 13-1的ISO米制螺纹的螺纹尾部和螺纹切槽》.pdf DIN 76-1-2016 Thread run-outs and thread undercuts - Part 1 For ISO metric threads in accordance with DIN 13-1《符合DIN 13-1的ISO米制螺纹的螺纹尾部和螺纹切槽》.pdf
  • DIN 76-2-1984 Thread run-outs and thread undercuts for pipe threads conforming to ISO 228 part 1《与ISO 228 第1部分相符的管螺纹的螺纹收尾和空刀槽》.pdf DIN 76-2-1984 Thread run-outs and thread undercuts for pipe threads conforming to ISO 228 part 1《与ISO 228 第1部分相符的管螺纹的螺纹收尾和空刀槽》.pdf
  • DIN 76-3-1977 Runouts Undercuts for Trapezoidal Threads Buttress Threads and Knuckle Threads and other Threads of Coarse Pitch《梯形螺纹、斜梯形螺纹和圆螺纹以及其他粗牙螺纹的螺纹尾部和螺纹退刀槽》.pdf DIN 76-3-1977 Runouts Undercuts for Trapezoidal Threads Buttress Threads and Knuckle Threads and other Threads of Coarse Pitch《梯形螺纹、斜梯形螺纹和圆螺纹以及其他粗牙螺纹的螺纹尾部和螺纹退刀槽》.pdf
  • DIN 7601-1998 Compression couplings with ball-type nipples - Complete unions and survey《带球形衬套的压接接头 完整接头和概述》.pdf DIN 7601-1998 Compression couplings with ball-type nipples - Complete unions and survey《带球形衬套的压接接头 完整接头和概述》.pdf
  • DIN 7603-2001 Sealing rings《密封环》.pdf DIN 7603-2001 Sealing rings《密封环》.pdf
  • DIN 7604-2016 Hexagon head screw plugs - Light type - Cylindrical thread《六角头螺塞 轻型 圆柱形螺纹》.pdf DIN 7604-2016 Hexagon head screw plugs - Light type - Cylindrical thread《六角头螺塞 轻型 圆柱形螺纹》.pdf
  • DIN 762-1-1992 Calibrated and tested round steel link chains for continuous conveyors grade 2 pitch 5d《连续输送机用经过校正和检验的链环节距为5d的2级圆钢链索》.pdf DIN 762-1-1992 Calibrated and tested round steel link chains for continuous conveyors grade 2 pitch 5d《连续输送机用经过校正和检验的链环节距为5d的2级圆钢链索》.pdf
  • DIN 762-1-2015 Round steel link chains - Round steel link chains pitch 5d for chain conveyors - Part 1 Grade 3 quenched and tempered《圆钢环链 链式输送机用节距为5d的圆钢环链 第1部分 3级 淬火和回火》.pdf DIN 762-1-2015 Round steel link chains - Round steel link chains pitch 5d for chain conveyors - Part 1 Grade 3 quenched and tempered《圆钢环链 链式输送机用节距为5d的圆钢环链 第1部分 3级 淬火和回火》.pdf
  • DIN 762-2-2015 Round steel link chains - Round steel link chains pitch 5d for chain conveyors - Part 2 Grade 5 quenched and tempered《圆钢环链 链式输送机用节距为5d的圆钢环链 第2部分 5级 淬火和回火》.pdf DIN 762-2-2015 Round steel link chains - Round steel link chains pitch 5d for chain conveyors - Part 2 Grade 5 quenched and tempered《圆钢环链 链式输送机用节距为5d的圆钢环链 第2部分 5级 淬火和回火》.pdf
  • 相关搜索

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

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