《最新《JAVA程序设计》课程考核答案.doc》由会员分享,可在线阅读,更多相关《最新《JAVA程序设计》课程考核答案.doc(22页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateJAVA程序设计课程考核答案郑州大学现代远程教育JAVA程序设计课程考核要求郑州大学现代远程教育JAVA程序设计课程考核要求说明:本课程考核形式为提交作业,完成后请保存为WORD 2003格式的文档,登陆学习平台提交,并检查和确认提交成功(能够下载,并且内容无误即为提交成功)。一 作业要求1.请独立自主完成作业。二 作业内容1. 简答题1) 什么是对象和消息?对象和消
2、息的关系是什么?答:对象:是数据以及可以对这些数据施加的操作结合在一起所构成的独立实体的总称。现实世界对象的两个特征:状态与行为。软件对象也具有状态与行为:状态:以一个或多个变量保存;行为:用方法实现行为。消息:消息是对象之间相互请求和相互协作的途径,要求某个对象执行类中所定义的某个操作的规格说明。消息由三部分构成:接收消息的对象、方法名称、方法的参数。消息是对象之间通信的唯一途径。2) 简述基于Swing技术的GUI应用程序基开发步骤。1、引入Swing 包:2、import javax.swing.*; 3、import java.awt.*; 4、import java.awt.even
3、t.*; 5、选择GUI的外观风格Look&Feel6、创建并设置顶级窗口容器7、创建与添加相关Swing组件8、实现相应的事件监听器类,将组件注册9、调整大小并显示顶层容器,将整个GUI界面显示出来。3) 常用的异常处理方法有哪些?答: 异常处理是指程序获得异常并处理,然后程序继续执行。常用异常处理方法:1)捕获并处理例外2)将方法中产生的例外抛出:声明异常和抛出异常1.异常处理:在Java语言的错误处理结构由try,catch,finally三个块组成。其中try块存放将可能发生异常的Java语言,并管理相关的异常指针;catch块紧跟在try块后面,用来激发被捕获的异常;finally块
4、包含清除程序没有释放的资源,句柄等。不管try块中的代码如何退出,都将执行 finally块。2. 读程序题1) 程序Assign,要求注释带标号1,2,3,4等的句子 ,并给出程序的运行结果。public class Assign public static void main (String args ) int x, y;float z=3.414f ; double w=3.1415; /1.声明并赋值double型变量 boolean truth=true; /2.生命并赋值boolean型变量 char c; String str; String str1=bye; /3.声明并赋
5、值string类变量 c=A; /4.给字符变量赋值 str=Hi out there; x=6; y=1000; System.out.println(x=+x); System.out.println(y=+y); System.out.println(z=+z); System.out.println(w=+w); System.out.println(truth=+truth); System.out.println(c=+c); System.out.println(str=+str); System.out.println(str1=+str1); 2) 读下面程序,从键盘输入5,
6、回车后输出的结果如何?从键盘输入quit,回车后程序执行情况如何?import java.io.*;public class Test public static void main(String args) throws IOException BufferedReader buf=new BufferedReader( new InputStreamReader(System.in); while(true) String str=buf.readLine(); if(str.equals(quit) break; int x=Integer.parseInt(str); System.o
7、ut.println(x*x); 答:回车后输出的结果是25.从键盘输入quit,回车后程序执行情况是终止应用程序的运行。3) 读程序,画图表示程序运行后的图形界面import java.awt.*; import javax.swing.*; public class T extends JFrame public T ( ) super(GridLayout); Container con=this.getContentPane(); con.setLayout(new GridLayout(2,3); con.add(new JButton(a); con.add(new JButton
8、(b); con.add(new JButton(c); con.add(new JButton(d); con.add(new JButton(e); con.add(new JButton(f); setSize(200, 80); setVisible(true); public static void main(String args) new T(); 3.程序设计题目1) 编程序实现,用Switch语句输出2000年2月所包含的天数。(要求适当加上程序注释。)import java.io.*;public class SwitchDemo2 public static void m
9、ain(String args) String s; int year = 2000; int month = 2; int numDays = 0; switch (month) case 1: case 3: case 5: case 7: case 8: case 10: case 12: numDays = 31; break; case 4: case 6: case 9: case 11: numDays = 30; break; case 2: if ( (year % 4 = 0) & !(year % 100 = 0) | (year % 400 = 0) ) numDays
10、 = 29; else numDays = 28; break; System.out.println(The date is +year+.2. The number of Days = + numDays); 2) 编写一个Rectangle类,含有一个点(point对象,创建方法p = new Point(0,0);),宽(width)和高(high),在其中完成下面功能: l 试着写至少一个构造方法;l 写出求矩形类的长、高、面积方法;public class Rectangleprivate int high,width ; private Point p;public Count(
11、 ) p = new Point(0,0);high = 0;width = 0;public Count(int high,int width,Point p ) this.p = p;this.high = 0;this.width = 0;public int Area()return high*width; public int getHighHH()return high; public int getWidth()return width; 3) 写一个Applet, 其完成功能就是在坐标(20,20)处打印出字符串:”Hello World!”;同时其可以作为一个Application运行,在控制台处打印出字符串:”Hello World!”。import java.applet.Applet;import java.awt.Graphics;public class Simple extends Applet public void paint(Graphics g) g.drawString(“Hello World!”, 20, 20); public static void main(String args) System.out.println(“Hello World!”); -
限制150内