Java 程序设计.doc_第1页
Java 程序设计.doc_第2页
Java 程序设计.doc_第3页
Java 程序设计.doc_第4页
Java 程序设计.doc_第5页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

郑州大学现代远程教育JAVA程序设计课程考核要求说明:本课程考核形式为提交作业,完成后请保存为WORD 2003格式的文档,登陆学习平台提交,并检查和确认提交成功(能够下载,并且内容无误即为提交成功)。一 作业要求1.请独立自主完成作业。二 作业内容1. 简答题1) 什么是对象和消息?对象和消息的关系是什么?答:对象:代码和数据的集合,就像现实生活中的一个实体。消息:进程之间的通信关系:消息用于对象之间的联系 如何理解呢,就是系统从主动对象的主动操作开始,当他需要其他对象去完成某些工作时,就可以发送消息,将控制点转移到接受消息的对象,完成工作。2) 简述基于Swing技术的GUI应用程序基开发步骤。答:1.引入swing包2选择“外观和感觉”3.设置顶层容器4.设置按钮和标签5.向容器中添加组件6.在组件周围添加边界 7.进行事件处理3) 常用的异常处理方法有哪些?答:1.在发生异常的地方直接处理;2.将异常抛给调用者3.异常常见的处理方法try 程序块 catch() 异常处理方式 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. boolean truth=true; /2. char c; String str; String str1=bye; /3. 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); 答: x=6 y=1000 z=3.414 w=3.1415 truth=true c=A str=Hi out there str1=bye 2) 读下面程序,从键盘输入5,回车后输出的结果如何?从键盘输入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.out.println(x*x); 答:程序有些问题的太浪费资源了输入的字符串是数字的话输出为数字的平方输入的字符串非数字就不会输出东西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(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(); 答:abcdef3.程序设计题目1) 编程序实现,用Switch语句输出2000年2月所包含的天数。(要求适当加上程序注释。)答:public class ABC public static void main(String args) int month=2,year=2000; boolean leap=false; leap=(year%400=0)|(year%100!=0)&(year%4=0);/判断今年是否为闰年还是平年 switch(month) case 1: System.out.print(year+年+1月份总的);break; case 2: System.out.print(year+年+2月份总的);break; case 3: System.out.print(year+年+3月份总的);break; case 4: System.out.print(year+年+4月份总的);break; case 5: System.out.print(year+年+5月份总的);break; case 6: System.out.print(year+年+6月份总的);break; case 7: System.out.print(year+年+7月份总的);break; case 8: System.out.print(year+年+8月份总的);break; case 9: System.out.print(year+年+9月份总的);break; case 10: System.out.print(year+年+10月份总的);break;case 11: System.out.print(year+年+11月份总的);break;case 12: System.out.print(year+年+12月份总的);break; default:System.out.print(无法打印);break; switch(month) case 1: case 3: case 5: case 7:case 8: case 10:case 12:System.out.println(有:31天);break; case 4: case 6: case 9: case 11:System.out.println(有:30天);break; case 2: if(leap) /2月份分为闰年和平年天数 System.out.println(有:29天); else System.out.println(有:28天); break; 2) 编写一个Rectangle类,含有一个点(point对象,创建方法p = new Point(0,0);),宽(width)和高(high),在其中完成下面功能: l 试着写至少一个构造方法;l 写出求矩形类的长、高、面积方法;答:class Rectangle double length;double width;public:Rectangle( double len = 10,double wid = 10 ) length = len; width = wid; double findArea() return length * width; ;3) 写一个Applet, 其完成功能就是在坐标(20,20)处打印出字符串:”Hello World!”;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论