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.
2009年6月15日 星期一
Lab Factorial
Lab Recursive method
2009年6月1日 星期一
Lab Modular Sorting
2009年5月25日 星期一
Lab: Static Method II
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).
2009年5月11日 星期一
Lab Static Method
Lab Math methods
2009年5月4日 星期一
Lab Method Overloading
2009年5月3日 星期日
2009年4月28日 星期二
2009年4月27日 星期一
Class definition 3
2009年4月25日 星期六
Homework 4-13-2009 Fraction Multiplication
2009年4月13日 星期一
lab Fraction equality test
Write a program to implement a method that can check whether 2 fractions are equal. You will implement a class called Fraction consisting of a numerator and a denominator. The equality test of 2 fractions should return a boolean value.
Use the following as the tests.
* 1/2, 2/4
* 5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
Use the following as the tests.
* 1/2, 2/4
* 5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
lab Fraction Addition
2009年3月30日 星期一
Homework 3-30-2009: counter
Define a class called Counter whose objects count things. An object of this class records a count that is a nonnegative integer. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Include an accessor method that returns the current count value and a method that outputs the count to the screen. Write a program to test
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
counter.reset();
counter.inc();
counter.inc();
counter.dec();
counter.output();
lab class definition 2
Study Display 4.4 (2nd ed. and 3rd ed.) or Display 4.2 & Display 4.3 (1st ed.) and then
1. Comment out date.setDate(6, 17, year); by // date.setDate(6, 17, year);
2. At the next line below, add date.readInput();
3. Run the program again. Fix any problems you may encouter along the way.
4. At the last line of your program, add System.out.println(date.month);
and see what happens. Why?
因為 month 使用 private 宣告,因此只能被同一個 class 存取。
1. Comment out date.setDate(6, 17, year); by // date.setDate(6, 17, year);
2. At the next line below, add date.readInput();
3. Run the program again. Fix any problems you may encouter along the way.
4. At the last line of your program, add System.out.println(date.month);
and see what happens. Why?
因為 month 使用 private 宣告,因此只能被同一個 class 存取。
2009年3月29日 星期日
Homework: 3/23/2009
2009年3月23日 星期一
Lab Cosine
Lab Fibonacci
2009年3月20日 星期五
Homework 3-16-2009
2009年3月17日 星期二
Lab Finding the max of a list of numbers
2009年3月16日 星期一
訂閱:
文章 (Atom)