Java语言设计实验指导书不含源代码_第1页
Java语言设计实验指导书不含源代码_第2页
Java语言设计实验指导书不含源代码_第3页
Java语言设计实验指导书不含源代码_第4页
Java语言设计实验指导书不含源代码_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

1、Java语言程序设计实验指导书福建农林大学计算机与信息学院2012-9文档可自由编辑打印实验一 Control Statements一、实验目的:1. Be familiar with JAVA developing environment2. Grasp switch statements and loop statements二、实验内容:数制转换问题,编写一个应用,接收用户输入的一个10进制数,然后分别把它转换为2进制、8进制和16进制数输出。三、实验要求:必须用分支结构和循环结果去实现数制转换,只要求能完成正整数的转换(如果有时间, double类型的数)。设计一个类DataTrans

2、fer,里面包括3个公共的类方法,分别把指的整数参数转换为2进制、8进制和16进制数,私有的类方法transfer2Other用于把第一个参数转换为由第二个参数指定的数制。比如,transfer2Other( 85, 2 )把85转化为2进制数。toBinary、toOctal和toHexadecimal都通过调用transfer2Other方法来完成。Transfer2Other方法的基本流程是:Str = “”;While ( num != 0) DoD = num % base;Str = toChar(D) + Str; /toChar是一个用户自定义函数,用于把数字转化为字符num

3、= num / base;End whileReturn str四、实验学时:2学时五、实验步骤:1、Edit the Java program;2、Compile Java program,find the syntactic errors in the program, record the main errors and correct them;3、Test the program using the pre-designed test case, find the logical errors in the program and correct them;4、Run the fin

4、al program, and analyze the results。实验二 Array一、实验目的:1. Grasp the declaration and usage of basic data types2. Grasp the declaration, definition, initialization and usage of Array3. Grasp the javadoc comments二、实验内容:设计一个类,包含一个元素类型为int的矩阵,设计一个方法把矩阵转置,重写方法toString(),使其能输出此矩阵。设计一个造成矩阵类Matrix,包含一个元素类型为int的

5、二维数组,分别设计一个静态方法和实例方法把矩阵转置,分别设计静态方法和实例方法实现二个矩阵相加、相乘。重写方法toString(),使其能输出此矩阵。三、实验要求:1. 体会静态方法和实例方法的设计2. 要求使用toString()方法、以二维形式输出转置前的矩阵和转置后的矩阵。四、实验学时: 2学时五、实验步骤:1、Edit the Java program;2、Compile Java program,find the syntactic errors in the program, record the main errors and correct them;3、Test the pr

6、ogram using the pre-designed test case, find the logical errors in the program and correct them;4、Run the final program, and analyze the results。实验三 Classes and Objects一、实验目的:1Grasp the overloading of constructors of classes2Grasp the Classes and Objects3. Grasp how to use UML tools in NetBeans二、实验内

7、容:设计一个复数类,能够完成复数之间的基本运算,重写方法toString(),使其能输出此复数(形式为: 实部 + 虚部i)。三、实验要求:要求设计的复数类必须有三个构造函数,分别为无参数、1个参数和2个参数的构造函数,完成的基本运算包括两个复数的加、减、乘和除法。四、实验学时:2学时五、实验步骤:1、Edit the Java program;2、Compile Java program,find the syntactic errors in the program, record the main errors and correct them;3、Test the program us

8、ing the pre-designed test case, find the logical errors in the program and correct them;4、Run the final program, and analyze the results。实验四 Inheritance and Polymorphism一、实验目的:1Grasp Inheritance of Object-Oriented Language2Grasp Overriding of Object-Oriented Language3. Grasp Polymorphism of Object-O

9、riented Language4Grasp the Implementation of Interface二、实验内容:设计一个抽象类Shape,包括2个抽象方法,分别是计算形状的周长和面积。设计具体类Rectangle和Circle,分别表示矩形和圆,它们都是Shapes的子类。使Rectangle和 Circle都实现Comparable接口(根据面积比较大小),编写一个通用的排序程序和一个通用的二分查找程序(自己写代码实现),能对这二种类型的数组进行排序并查找指定的对象。三、实验要求:要求适当设置属性及方法的访问属性,掌握方法重写,体会继承在软件复用中的优点的不足,体会多态的“通用编程

10、”思想。四、实验学时:2学时五、实验步骤:1、Edit the Java program;2、Compile Java program,find the syntactic errors in the program, record the main errors and correct them;3、Test the program using the pre-designed test case, find the logical errors in the program and correct them;4、Run the final program, and analyze the

11、results。实验五 GUI Programming一、实验目的:1. Grasp the usage of GUIcomponent2. Understand the designing of GUI event-driving programming3. Understand MVC(Model-View-Controller)model二、实验内容:采用MVC的方式重新实现地址薄维护程序。界面如图1所示:图1 地址薄应用程序的用户界面MVC三者之间的关系可参考图2。视图类AddressBookJFrame中的方法setAddress用于将参数的值在界面上显示,而方法getAddress

12、()用于将界面上的值生成一个Address类型的对象。在控制器AddressBookController中有相应的实现了ActionListerner接口的类(如图3),用来侦听视图中相应命令按钮的事件,视图中的一类add方法(如addAddActionListerner)用于注册侦听器。对模型,书中的例子是用随机访问文件,你可以使用数据库,通过JDBC建立与数据库的连接;也可以用顺序文本文件,先把文件读入到一个Collection(如ArrayList)中,再在从集合上读指定位置记录,或者把记录添加到集合中,最后再把集合中的数据写入文件中。图2是模型-视图-控制器参考实现图图2 模型-视图-

13、控制器参考实现图图3是侦听Add按钮和First按钮的侦听器例 class AddActionListener implements ActionListener public void actionPerformed(ActionEvent e) Address address; try address = addressBookJFrame.getAddress(); addressBookModel.writeAddress(address); catch (IOException ex) ex.printStackTrace(); class FirstActionListener i

14、mplements ActionListener public void actionPerformed(ActionEvent e) Address address; try address = addressBookModel.readFirst(); addressBookJFrame.setAddress(address); catch (IOException ex) ex.printStackTrace(); 图3 侦听Add按钮和First按钮的侦听器例三、实验要求:利用类图、状态图等去描述系统,理解面对对象的建模过程,体会设计模式对软件设计的意义。四、实验学时:2学时五、实验步骤:1、Edit the Java program;2、Compile Java program,find the syntact

温馨提示

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

评论

0/150

提交评论