星期一, 1月 08, 2007

Lab Hanoi Tower

The pseudocode for Hanoi Tower is as follows:
Solve(N, Src, Aux, Dst)
if N is 0 return
Solve(N-1, Src, Dst, Aux)
Move N from Src to Dst
Solve(N-1, Aux, Src, Dst)

Write the Java program based on the pseudocode in the above.

Lab Squared Array

Write a program that given an array of integers, return the squares of the array.
The sqaures are computed in a separate method rather than in the main method.

星期一, 12月 25, 2006

Lab Sorting

Study Display 6.1, and then write a program that can sort numbers in ascending order.

星期一, 12月 18, 2006

sample code of a class with static methods

public class RoundStuff
{
public static final double PI=3.14159;

public static double area(double radius)
{
return (PI*radius*radius);
}

public static double volume(double radius)
{
return((4.0/3.0)*PI*radius*radius*radius);
}
}

Lab Static Method, Part II

(1st ed.) Do Project 3 of Chap 5. Define a Complex class and write a program to compute (2+3i)+(4+5i) in Java.
(2nd ed.) Do Project 7 of Chap 5. Define a Complex class and write a program to compute (2+3i)+(4+5i) in Java.

Note:
Implement a static method and a nonstatic method using overloading. The results of these two methods should be the same.

Lab Static Method

Study Display 5.2.
Using static variables and static methods to implement the class Fibonacci such that
the first call to Fibonacci.next()
returns 2, the second returns 3, and then 5, and so on.