Define a Complex class with a static method for computing complex addition. Use (2+3i)+(4+5i) in your test.
2007年12月28日 星期五
Lab Static Method
Homework 12/21/2007
2007年12月21日 星期五
Lab Java Constructor
2007年12月14日 星期五
Homework 12-7-2007
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);
Use the following as the tests.
1/2, 2/4
5/6, 6/7
Hints:
Fraction f1, f2;
f1.equals(f2);
lab Fraction Addition
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
加了六次減一次 執行結果為5
加了六次減一次 執行結果為5
Class Definition 3
Homework 11/16/2007: 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?
因為我們在class裡面定義month為private variable 所以欄位 DateThirdTry.Month 是不可見的
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?
因為我們在class裡面定義month為private variable 所以欄位 DateThirdTry.Month 是不可見的
2007年11月21日 星期三
2007年11月16日 星期五
2007年11月9日 星期五
Homework 10-26-2007
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.Without any change made to your program, your program should be able to process a new set of data, such as follows:
M 52,000
M 35,000
F 48,000
M 33,000
F 75,000
F 110,000
F 90,000
M 30,100
Lab Exponential Function
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.Without any change made to your program, your program should be able to process a new set of data, such as follows:
M 52,000
M 35,000
F 48,000
M 33,000
F 75,000
F 110,000
F 90,000
M 30,100
Lab Exponential Function
2007年10月26日 星期五
Lab 9*9
Lab Fibonacci numbers
Homework 10-12-2007: Finding the max and the min
Bonus: Lab for-loop
2007年10月12日 星期五
Lab: Tax Calculation
Quiz 10-12-2007
先輸入的為i 後輸入的為j
2. The identifier BufferedReader is normally abbreviated as BR in programming language C. However, Java programmers normally do not use abbreviations for identifiers. What are the advantages and disadvantages of not using abbreviations?
在過去電腦還不發達的年代,C語言中使用縮寫是要節省記憶體的損耗
而JAVA不使用縮寫的好處是可讓人淺顯易懂,壞處是佔記憶體。
2007年10月5日 星期五
Lab: Keyborad Input
Lab: Scanner
Lab: Adding Links on Your Blog
2007年9月28日 星期五
Homework 9-28-2007 String Processing
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.
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 9-28-2007 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.
Ans:
如果是4000feet的話,需要3787.878787878788元
如果是6000feet的話,需要5681.818181818182元
Hint: There are 5280 feet in a mile.
Ans:
如果是4000feet的話,需要3787.878787878788元
如果是6000feet的話,需要5681.818181818182元
Homework 9/21/2007
"tell me and I'll forget; show me and I may remember; involve me and I'll understand"
1. Explain bytecode, JVM
Byte-Code:可將我們所寫的程式經過編譯後產出的中間碼。
JVM:Java Virtual Machine.一個以軟體模擬出來的機器環境,可用來執行java 的 byte code。
2. Explain class, object
class是object的集合,用來描述屬性(Property)跟方法(Method)。
object是物件,包含在CLASS裡
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
1. Explain bytecode, JVM
Byte-Code:可將我們所寫的程式經過編譯後產出的中間碼。
JVM:Java Virtual Machine.一個以軟體模擬出來的機器環境,可用來執行java 的 byte code。
2. Explain class, object
class是object的集合,用來描述屬性(Property)跟方法(Method)。
object是物件,包含在CLASS裡
4.1 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (i++);
Print i;
Ans: 2, 4, 3
4.2 Write a Java program as follows:
Let i=2;
Print i;
Print 2 * (++i);
Print i;
Ans: 2, 6, 3
4.3 Write a Java program as follows:
Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;
Ans: 3.5, 3.5
訂閱:
文章 (Atom)