实验一类的封装-福建农林大学.doc

实验一类的封装-福建农林大学.doc

《Java语言程序设计》 实验指导书 福建农林大学 计算机与信息学院 2011-3 实验一 Control Statements 一、实验目的: 1. Be familiar with JAVA developing environment 2. Grasp switch statements and loop statements 二、实验内容: 数制转换问题,编写一个应用,接收用户输入的一个10进制数,然后分别把它转换为2进制、8进制和16进制数输出。 三、实验要求: 必须用分支结构和循环结果去实现数制转换,只要求能完成正整数的转换。 设计一个类DataTransfer,里面包括3个公共的类方法,分别把指的整数参数转换为2进制、8进制和16进制数,私有的类方法transfer2Other用于把第一个参数转换为由第二个参数指定的数制。比如,transfer2Other( 85, 2 )把85转化为2进制数。toBinary、toOctal和toHexadecimal都通过调用transfer2Other方法来完成。 Transfer2Other方法的基本流程是: Str = “”; While ( num != 0) Do D = num % base; Str = toChar(D) + Str; //toChar是一个用户自定义函数,用于把数字转化为字符 num = num / base; End while Return 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 program, and analyze the results。 实验二 Array 一、实验目的: 1. Grasp the declaration and usage of basic data types 2. Grasp the declaration, definition, initialization and usage of Array 3. Grasp the javadoc comments 二、实验内容: 设计一个类,包含一个元素类型为int的矩阵,设计一个方法把矩阵转置,重写方法toString(),使其能输出此矩阵。设计一个造成矩阵类Matrix,包含一个元素类型为int的二维数组,分别设计一个静态方法和实例方法把矩阵转置,分别设计静态方法和实例方法实现二个矩阵相加、相乘。重写方法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 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 一、实验目的: 1.Grasp the overloading of constructors of classes 2.Grasp the Classes and Objects 3. Grasp how to use UML tools in NetBeans 二、实验内容: 设计一个复数类,能够完成复数之间的基本运算,重写方法toString(),使其能输出此复数(形式为: 实部 + 虚部i)。 三、实验要求: 要求设计的复数类必须有三个构造函数,分别为无参数、1个参数和2个参数的构造函数,完成的基本运算包括两个复数的加、减、乘和除法。 四、实验学时:2学时 五、实验步骤:

文档评论(0)

1亿VIP精品文档

相关文档