2009年6月16日 星期二

Lab Hanoi Tower

The pseudocode for Hanoi Tower is as follows:solve(N, Src, Aux, Dst)if N is 0 returnsolve(N-1, Src, Dst, Aux)Move N from Src to Dstsolve(N-1, Aux, Src, Dst)Write the Java program based on the pseudocode in the above.

Lab Factorial

Write a Java program that computes N! where N is a positive integer.Hint:public static long factorial(int n)

Lab Recursive method


Write a recursive method to compute Fibonacci series.Hint:1.fib(n)=fib(n-1)+fib(n-2)2.public static long fib(int n)

2009年5月26日 星期二

Lab Magic Parking Tower

A parking tower is out of order someday. If you park a Benz, you will end up with a Torben. Write a program to simulate this scenario. First create a class called CarParked which has a static method called outOfOrder. Name an object called yourCar, which happens to be a Benz. Your program should contain a class called CarParked and a test program called CarParkedDemo which test the method by CarParked.outOfOrder(yourCar).Hint: You may study Display 5.14 to get some ideas.





2009年5月13日 星期三

Lab Static Method




Define a Complex class with a static method for computing complex addition. Use (2+3i)+(4+5i) in your test.