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.
2009年6月16日 星期二
Lab Recursive method
2009年6月7日 星期日
2009年6月2日 星期二
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日 星期三
2009年5月6日 星期三
2009年5月4日 星期一
2009年4月27日 星期一
Class definition 3
Homework 4-13-2009 Fraction Multiplication
Write a program to implement a method that can multiply 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The multiplication of2 fractions should be equal to a fraction.Use 1/2 * 1/3 as the test.Hints:Fraction f1, f2;f1.multiply(f2);due date: 4/27/2009
2009年4月14日 星期二
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/7Hints:Fraction f1, f2;f1.equals(f2);
lab Fraction Addition
2009年4月6日 星期一
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 testcounter.reset();counter.inc();counter.inc();counter.dec();counter.output();
2009年3月30日 星期一
lab class definition 2
Study Display 4.4 (2nd ed. and 3rd ed.) or Display 4.2 & Display 4.3 (1st ed.) and then1. 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?
2009年3月29日 星期日
2009年3月26日 星期四
Lab Cosine
Lab Fibonacci
List the first 100 numbers and the ratio ofa number to its previous number, such as 1/1 = 1, 2/1 = 2, 3/2 = 1·5, 5/3 = 1·666..., 8/5 = 1·6, 13/8 = 1·625, 21/13 = 1·61538....Want to know more about Fibonacci number
2009年3月22日 星期日
2009年3月16日 星期一
Lab Finding the max of a list of numbers
訂閱:
文章 (Atom)