
禁止使用電子計算器。
不必抄題,作答時請將試題題號及答案依照順序寫在試卷上,於本試題上作答者,不予計分。
一、定義下述文法(grammar):
expression → expression + expression | expression - expression | type
type → int | double
根據上面之文法,請畫出 int + int + int 兩個不同的剖析樹(parsing tree)。(10 分)
根據上面之文法,請導出所有只包含 2個type 之expression 的結果。該
expression 一個 type 為int,另一 type 為double。(10 分)
請說明何謂模稜兩可的文法(ambiguous grammar)。(5分)
二、網際網路程式與應用的發展,結合了許多技術與分析方法,請用數行文字,說明下
列幾個網際網路應用技術的專有名詞:
說明 HDFS 英文全名,其架構元素與基本運作特性。(8分)
說明 MapReduce 的特性及 Map 和Reduce 的運作方式。(8分)
說明 NO SQL 的英文全名及其特性。(9分)
三、請以物件導向,多型(polymorphism)的技術,改寫下列計算薪水的程式,其中經
理(manager)薪水是 40000,工程師(engineer)薪水是 35000。
int getPay(String employeeType) {
if (employeeType ==“manager”) {
return 40000;
else if (employeeType == “engineer”)
return 35000;
}
設計 Employee, Manager, Engineer 等三個類別及其屬性(attribute)與方法(method),
方法包括建構子(constructor)。其中 Employee 是抽象類別,有一個保護
(protected)屬性薪水(salary);Manager 和 Engineer 是Employee 的子類別。
(18 分)
畫出 UML 類別圖。(7分)

四、例外(exception)處理的應用:
試說明 Java 對於例外處理的抓取或宣告規則(catch or declare rule)。(7分)
填寫下列空格,完成以下 inputScore 方法。該程式要求使用者輸入成績,若輸入為
非數字,則拋出例外(exception)警示,迴圈繼續,直到使用者輸入合理的數字成
績。若輸入的成績沒有介於 0-100 間,則把例外向上拋給呼叫的方法。(18 分)
public static void inputScore () (1) {
String str;
boolean valid;
double score = 0;
Scanner sc = new Scanner(System.in);
do {
valid = true;
System.out.println("Input the score");
str = sc.next();
try {
score = Double.parseDouble(str);
} catch ( (2) ) {
System.out.println(e);
valid = false;
}
} while ( (3) );
if (score >100 || score <0) throw (4) ("分數未介於 0-100 間");
System.out.println(score);
}