2008年12月22日 星期一

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.


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)


2008年12月12日 星期五

Lab Static Method

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




2008年11月28日 星期五

Lab Java Constructor

Use Display 4.14 to call 4.13 (2nd ed.) or
Display 4.12 to call 4.11 (1st ed.).

After you finish the above, try the following

Date birthday = new Date("Jan",1,2000);
birthday.Date("Feb",1,2000);
birthday.setDate("Feb",1,2000);
birthday=new Date("Mar",1,2000);



Lab Overloading

Do Display 4.11



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.



2008年11月21日 星期五

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);




lab Fraction Addition

Write a program to implement a method that can do additions of 2 fractions. You will implement a class called Fraction consisting of a numerator and a denominator. The additions of
2 fractions should be equal to a fraction.
Use 1/2+1/3 as the test.

Hints:
Fraction f1, f2;
f1.add(f2);



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?




2008年11月7日 星期五

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?



lab 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();



Homework 10-31-2008

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


2008年10月25日 星期六

Homework 10-24-2008

1. 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.



2. Write a program to generate the following table of arithmetic expressions

1*1=1 1*2=2 1*3=3 ... 1*9=9
2*1=2 2*2=4 2*3=6 ... 2*9=19
...
9*1=9 9*2=18 9*3=27 ... 9*9=81

2008年10月24日 星期五

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,000,000


2,000,000

2008年10月23日 星期四

Homework 10-3-2008

3. Do Project 4 in Chapter 2

4. Do Project 5 in Chapter 2

5. Do Project 6, in Chapter 2

6. Do Project 7, in Chapter 2

2008年10月3日 星期五

Lab: Numerical Method

Project 1 of Chap. 2.

Lab Keyboad processing

Project 3 of Chap. 2.

Lab Keyboard Input

1.
Do Display 2.6.



2.
Rewrite Display 2.6 using BufferedReader.

2008年9月27日 星期六

Homework 9-26-2008

1. Complete Lab String Processing.



2. Write a program that can reverse the order of an input string. For example, if you input "ab", it will output "ba".
輸入任意字串後,顛倒輸出。

2008年9月26日 星期五

Lab: String Processing

Do Project 5 of Chap. 1 on Page 56.

Write a program that starts with a line of text and then outputs that line of text with the first occurrence of "hate" changed to "love". For example, a possible sample output might be

The line of text to be changed is:
I hate you.
I have rephrased that line to read:
I love you.

Hint: You may consider use the methods: indexOf(A_String) and substring(Start, End) in your program.


Lab: Simple Arithmetics

Write a Java program that displays the results of the expressions 15/4, 4/15, 15%4, 4%15. Calculate the values of these expressions manually to verify that the displayed values are correct.

Lab: Simple Calculation

Suppose you are a landscape architect who charges $5,000 per mile to landscape a highway, and suppose you know the length in feet of the high way you are working on. Write a Java program to calculate the price you charge when the length is 6000 and 4000, respectively.

Hint: There are 5280 feet in a mile.

2008年9月25日 星期四

Homework 9-19-2008

1.Explain bytecode, JVM
Ans:
JVM(Java Virtual Machine) Java虛擬機器
JAVA為了解決跨平台的問題,開發了一個假的電腦,即是Java虛擬機器。
故Java程式在轉譯時,不是轉成真正電腦的機器碼,而是Java虛擬機器的機器碼(ByteCode)。

2. Explain class, object
Ans:
class 類別
object 物件
類別與物件 是物件導向的基本概念
"類別"像是種類,例如 : 人類、魚、飛機、等等...
而"物件"屬於各種類別,例如:每個人都是個物件 是屬於"人"的類別
但是每個人的性別、長相、膚色不盡相同,且能力也不同,
就如同物件導向裡,可以有不同的屬性與方法,因此每個人都是個獨立的物件。

4.1


4.2


4.3

2008年9月19日 星期五

Lab2

Lab1

2008年9月12日 星期五

自我介紹

電子四丙 莊傑雄 9426363
以前在上計算機概論就對C語言非常有興趣,也曾自己借書來研究過
但對於物件導向比較陌生,這學期很開心能選到JAVA,近年來JAVA也
是非常的熱門,所以希望這學期能好好學習。