2009年6月15日 星期一

Lab 29 : 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 28 : Factorial

Write a Java program that computes N! where N is a positive integer.

Hint:

public static long factorial(int n)


Lab 27 : 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年6月1日 星期一

Lab 26 : Modular Sorting

Write a sort method which takes a double array as parameter
and returns the sorted array. Call this method in a main program.

Hint: The lab is a rewriting of Lab Sorting
to make the sorting procedure a reusable method।

main Class:


Array Class:

Lab 25 : Array

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

2009年5月25日 星期一

Lab 24 : Static Method II

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

main:


Complex Class:

Lab 23 : 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.

main:

CarParked Class: