2007年12月28日 星期五

Lab: Static Method II

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



Lab Static Method

Study Display 5.2.
Using static variables and static methods to implement the class
Fibonacci such that
the first call to Fibonacci.next()
returns 2, the second returns 3, and then 5, and so on.



2007年12月27日 星期四

Homework 12/21/2007

Design a method that can compute the vector inner product.
You must define Vector class in the first place.
Write a demo program to verify your program works.
You should use constructors to initialize the two vectors.

Hint: The inner product is not a vector. It is a number (scalar).


2007年12月21日 星期五

Lab Java Constructor

Use Display 4.14 to call 4.13 (2nd ed.) orDisplay 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);



2007年12月12日 星期三

Homework 12-7-2007

1. Define a Complex class and write an object oriented program to compute (2+3i)+(4+5i) in Java.

2007年12月7日 星期五

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 of2 fractions should be equal to a fraction.Use 1/2+1/3 as the test.
Hints:
Fraction f1, f2;
f1.add(f2);


Homework 11-30-2007










2007年11月30日 星期五

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


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?










Homework 11/16/2007: lab class definition 2

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?
由於前面的類別宣告為private的關係,private具有保密的作用,
而不讓user任意查看資料內容,所以程式才會發生錯誤,如果將
private改成public,則就能印出date.month的內容囉!!













2007年11月16日 星期五

2007年10月12日 星期五

Lab Finding the max of three numbers


Lab: Tax Calculation


Quiz(第一題)


Quiz(第2題)

2.
優點:寫程式時使用縮寫可以減少程式碼的長度,一旦程式碼長度變短,所佔記憶體的空間就變小
缺點:要是程式碼使用縮寫時,會讓別人觀看你的程式碼時不一定知道那個縮寫跟妳要表達的一不一樣,例如 BufferedReader 的縮寫是BR,但是也有縮寫是BR的另一個字,所以在沒有在程式碼後面加上註解的話,寫縮寫會讓別人產生混淆

Project 3 of Chap. 2.