2007年10月5日 星期五

Lab: Keyborad Input


Enter the number of pods:
the number of peas in a pod:
10
20
10 pods and 20 peas per pod.
The total number of peas = 200

Lab: Scanner


Enter the number of pods followed by
the number of peas in a pod
50 21
50pods and21peas per pod
The total number of peas =1050

Lab: Adding Links on Your Blog

1. Check into your blog homepage.
2. Enter "自訂"
3. Select "連結清單"
4. Write down "http://javaatcycu.blogspot.com/" and the title as "Java物件導向程式設計"
5. Also add your own favorite links.

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.

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元

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

2007年9月21日 星期五

Lab 2



所以老鼠如果一天吃了10g的人工代糖會死去
也就是大約喝了10公升的汽水
如今假設一個人的體重為80kg
則要喝多少汽水才會死去?
所以人一天大約要喝8000公升就會有生命危險