顯示具有 《JAVA》隨堂製作 標籤的文章。 顯示所有文章
顯示具有 《JAVA》隨堂製作 標籤的文章。 顯示所有文章

2009年6月15日 星期一

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.



From =JAVA=

Lab Factorial

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

Hint:

public static long factorial(int n)



From =JAVA=

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)



From =JAVA=

2009年6月2日 星期二

Lab Array

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









From =JAVA=

2009年5月25日 星期一

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月12日 星期二

Lab Finding the max of three numbers

Write a static method that computes the maximum of three float numbers.






點此打開==>
From =JAVA=

Lab Static Method

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





點此打開=>









點此打開=>

2009年5月11日 星期一

Lab Math methods

Compute the following mathematical functions.

Math.round(3.2)
Math.round(3.6)
Math.floor(3.2)
Math.floor(3.6)
Math.ceil(3.2)
Math.ceil(3.6)








點此打開=>

2009年5月5日 星期二

Lab Method Overloading

依據Class definition 3,修改程式使其接受三種setDate

date1.setDate(1,2,2008);
date2.setDate("February",2, 2008);
date3.setDate(2008);










2009年5月4日 星期一

Lab Java Constructor

Write constructors in the lab Fraction Addition.


(Fraction)


(FractionDemo)

    =>將原本的程式改寫用"Fraction f1 = new Fraction (1, 2)"的方式

     還要記得設定初始值!

2009年4月27日 星期一

Class definition 3

Do Display 4.7 (3rd, 2nd ed.) or 4.5 (1st ed.). Then use Display 4.8 to call 4.7. Question In Display 4.7, if the method setDate has the parameter as setDate(int month, int day, int year), what kind of changes should be made in its body of codes?

Lab ADT

Define a Complex class and write an object oriented program to compute (2+3i)+(4+5i) in Java. The methods should include an access and a mutator.






2009年3月31日 星期二

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被定義為只有自己可以呼叫自己,所以再另一個程式裡無法呼叫







2009年3月30日 星期一

lab class definition

Study Display 4.1 and then do Self-Test Exercise 1.







範例4-1

增加一個宣告的函數makeItNewYear( )








2009年3月23日 星期一

Lab Cosine

Write a Java program to calculate the triangular function as follows:
Cos(x)=1 - x 2 /2!+ x 4/4!- x 6/ 6!...

Lab Fibonacci

Write a program to generate the series 1, 1, 2, 3, 5, 8, 13, ...
The series has a property that the third number is the sum of the first and second numbers. For example, 2=1+1, 3=1+2, and 5=2+3.




*結論:差距越來越小逐漸趨近於0

2009年3月16日 星期一

Lab Finding the max of a list of numbers

Based on your study of Display 3.8, write a code to find the max and min of a list of number.
For example, given 1,3,5, and9, the max is 9 and the min is 1.
Your program should be able to process a list of any length.




Lab Finding the max of three numbers

Write a program to decide the max number of the three input number.




Lab Tax Calculation

Study Display 3.1. Based on the income tax rate in Taiwan,
calculate the income tax of a person whose annual income is 1,000,000 or 2,000,000.


(1)年收入:1000000


(2)年收入:2000000




2009年3月9日 星期一