顯示具有 Homework 標籤的文章。 顯示所有文章
顯示具有 Homework 標籤的文章。 顯示所有文章

2009年5月10日 星期日

Homework 10

Do Project 7 of Chapter 4।

main Class:





Temperature Class:




2009年5月3日 星期日

Homework 9

Do project 2 of Chapter 4.

強烈要求同學一定要親自動手做,鼓勵同學將理論與實作密切配合。
相信只要同學真正的努力用功,縱使資質稍差,應該都可以學到Java程式設計之知識

main Class:


Fraction Class:


2009年4月25日 星期六

Homework 8 : 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 of
2 fractions should be equal to a fraction.
Use 1/2 * 1/3 as the test.

Hints:
Fraction f1, f2;
f1।multiply(f2);

兩數相乘後利用輾轉相除法取分子、分母的最大公因數進行約分




1/2 * 1/3 = 1/6

8/7 * 3/4 = 6/7

2009年3月30日 星期一

Homework 7 : 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();

2009年3月27日 星期五

Homework 6

Write a program to calculate average income by gender based on the following data, where F stands for female and M for male.

F 62,000
M 25,000
F 38,000
F 43,000
M 65,000
M 120,000
F 80,000
M 30,100

You should be able to allow users to type in a whole line such as F 80,000 followed by next line M 30,100।

2009年3月21日 星期六

Homework 5

1. Project 7 of Chap. 3

for n=1 and n=10

for n=50 and n=100

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

2009年3月15日 星期日

Homework 4

1. Do Project 4 in Chapter 2


2. Do Project 5 in Chapter 2


3. Do Project 6, in Chapter 2


4. Do Project 7, in Chapter 2

2009年3月7日 星期六

Homework 3

1. Write a program that can reverse the order of an input string. For example, if you input "ab", it will output "ba". If you input "abcdefg", it should return "gfedcba".



2. Write a program that can print names alternatively. The names are in the format of "First Name + Last Name" or "Last Name, First Name". For example, if you input "Walt Savitch", your program will output "Savitch, Walt". If you input "Savitch, Walt", your program will output "Walt Savitch".

2009年3月2日 星期一

Homework 2

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


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


15/4算出來的結果為3.75。
4/15算出來的結果為0.266666666...6,程式用浮點數值只算到小數點第八位,會有誤差而得到的結果為0.26666668。
15%4為15/4的值取餘數,與程式計算結果一樣為3。
4%15為4/15的值取餘數,與程式計算結果一樣為4。

2009年2月18日 星期三

Homework 1

1. 兩年前寫了幾篇文章,探討為什麼要學寫程式。參考之後,也描述一下你對寫程式的看法。
以前修課的時候有位教授常問我們說: 你們覺得自己電子系讀完四年可做些什麼?出去要拿什麼跟人家競爭? 其實你只要能學會擅長寫程式或是有辦法自己設計高等電路在這個行業就有飯吃。 正如老師們所說的,學寫程式是相當重要的。如果說硬體是BODY的話,那麼驅動程式就是SOUL了,它深深主宰著硬體執行起來的良莠。而且程式蘊含著程式設計者的高度智慧,為了開發出讓人更能享受這些電子產品無不絞盡腦汁。像我們在做電路設計時,都得先學會業界的一些設計用的模擬軟體,不僅大大地將近實做時的錯誤率,更能設計出更有效率的電路。 而為了做什麼樣子的硬體,便持續開發什麼樣子的軟體,如此相互扶持著造就電子業蓬勃發展。

2. 參考課本第一章,回答以下問題

a. What is Java Virtual Machine and Java Bytecode?
Java Virtual Machine就是一個專屬於JAVA系統的虛擬電腦 ,它有它自己所能理解的Machine Language,這個Machine Language就是Java Bytecode。
簡單來說當我們寫完JAVA的程式碼以後,經過compiler編譯成Bytecode這個Machine Language,而且又因為Java Virtual Machine非常近似於一般我們所使用的電腦,因而可輕易將Bytecode轉換成一般電腦的Machine Language去執行了。

b. Explain Java's feature "Write once、run anywhere."
指Java Language只要寫過一次之後,程式就可以在各種平台上運行,這種跨平台的程式語言實在是既方便又好用。