Java语言设计实验指导书(不含源代码).doc

上传人:自*** 文档编号:124920753 上传时间:2020-03-14 格式:DOC 页数:10 大小:701KB
返回 下载 相关 举报
Java语言设计实验指导书(不含源代码).doc_第1页
第1页 / 共10页
Java语言设计实验指导书(不含源代码).doc_第2页
第2页 / 共10页
Java语言设计实验指导书(不含源代码).doc_第3页
第3页 / 共10页
Java语言设计实验指导书(不含源代码).doc_第4页
第4页 / 共10页
Java语言设计实验指导书(不含源代码).doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《Java语言设计实验指导书(不含源代码).doc》由会员分享,可在线阅读,更多相关《Java语言设计实验指导书(不含源代码).doc(10页珍藏版)》请在金锄头文库上搜索。

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

2、个公共的类方法,分别把指的整数参数转换为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 = num / b

3、ase;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 final progra

4、m, 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 program usi

6、ng 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 using the p

8、re-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-Oriented L

9、anguage4Grasp 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 results。实

11、验五 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 implements

14、 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 syntactic errors in the program, record the main errors and correct them;3、Test the program using the pre-designed test case, find the l

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 往来文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号