106年 鐵路特考 員級 資訊處理 程式設計概要 試卷

pdf
90.79 KB
5 頁
MIS
侵權投訴
加載中. ..
PDF
106年公務人員特種考試警察人員一般警察
人員考試及106年特種考試交通事業鐵路
人員、退除役軍人轉任公務人員考試試題 代號:80850 全五頁
第一頁
考試別 鐵路人員考試
等別 員級考試
類科別 資訊處理
科目 程式設計概要
考試時間 1 小時 30
※注意:
禁止使用電子計算器。
不必抄題,作答時請將試題題號及答案依照順序寫在試卷上,於本試題上作答者,不予計分。
(請接第二頁)
一、就下列 Java 程式片斷中加入一個 for 迴圈,使其印出右側結果。15 分)
public class AllNumbers number square cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
{ public static void main( String[] args )
{ // print a header for the table
System.out.printf( "%st%st%sn", "number", "square", "cube" );
// 加入一個 for 迴圈
//
//
} // end main
}
二、承題一,試於 for 迴圈內加入 if 判斷敘述,以顯示下列結果:10 分)
numbe
r
s
q
uare cube
3 9 27
6 36 216
9 81 729
三、下列程式能將輸入的字串 input=”abcdef”,反向列印為”fedcba”。試以遞迴的方式撰
寫副程式 stringReverseHelper,且其參數宣告必須與 stringReverse 方法內的呼叫一
致。25 分)
public class Reverse
{ public static void stringReverse( char[] array )
{ stringReverseHelper( array, 0 );
System.out.println();
}
//stringReverseHelper 副程式的放置處
public static void main( String args[] )
{ String input = "abcdef";
stringReverse( input.toCharArray() );
} // end main
} // end class Reverse
106年公務人員特種考試警察人員一般警察
人員考試及106年特種考試交通事業鐵路
人員、退除役軍人轉任公務人員考試試題 代號:80850 全五頁
第二頁
考試別 鐵路人員考試
等別 員級考試
類科別 資訊處理
科目 程式設計概要
四、下列網頁按 button 鍵前、後瀏覽器顯示的結果為何?(10 分)
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change HTML content.</p>
<button type="button"
onclick=&apos;document.getElementById("demo").innerHTML="Hello JavaScript!" &apos;>Click Me!</button>
</body>
</html>
五、根據下列程式回答問題:
Employee, HourlyEmployee, SalariedEmployee 三個類別的關係為何?(5分)
試指出一個建構子,並說明它的作用。5分)
試說明 SalariedEmployee super(n)的作用。5分)
試指出多型(polymorphism)出現的地方。5分)
執行 PayrollSystemTest 後印出的結果為何?(10 分)
public abstract class Employee
{ private String name;
public Employee( String n )
{ name = n;
}
public void setName( String str )
{ name = str;
}
public String getName()
{ return name;
}
@Override
public String toString()
{ return String. format( "%s", getName() );
}
public abstract double earnings();
}
請接第三頁
106年公務人員特種考試警察人員一般警察
人員考試及106年特種考試交通事業鐵路
人員、退除役軍人轉任公務人員考試試題 代號:80850 全五頁
第三頁
考試別 鐵路人員考試
等別 員級考試
類科別 資訊處理
科目 程式設計概要
(請接第三頁)
public class HourlyEmployee extends Employee
{ private double wage; // wage per hour
private double hours; // hours worked for week
public HourlyEmployee( String n, double hourlyWage, double hoursWorked )
{ super( n );
setWage( hourlyWage );
setHours( hoursWorked );
}
public void setWage( double hourlyWage )
{ if ( hourlyWage >= 0.0 )
wage = hourlyWage;
else
throw new IllegalArgumentException("Hourly wage must be >= 0.0" );
}
public double getWage()
{ return wage;
}
public void setHours( double hoursWorked )
{ if ( ( hoursWorked >= 0.0 ) && ( hoursWorked <= 168.0 ) )
hours = hoursWorked;
else
throw new IllegalArgumentException("Hours worked must be >= 0.0 and <= 168.0" );
}
public double getHours()
{ return hours;
}
@Override
public double earnings()
{ if ( getHours() <= 40 ) // no overtime
return getWage() * getHours();
else
return 40 * getWage() + ( getHours() - 40 ) * getWage() * 1.5;
}
@Override
public String toString()
{ return String. format( "hourly employee: %sn%s: $%,.2f; %s: %, .2f",
super.toString(), "hourly wage", getWage(),"hours worked", getHours() );
}
}
請接第四頁
106年公務人員特種考試警察人員一般警察
人員考試及106年特種考試交通事業鐵路
人員、退除役軍人轉任公務人員考試試題 代號:80850 全五頁
第四頁
考試別 鐵路人員考試
等別 員級考試
類科別 資訊處理
科目 程式設計概要
public class SalariedEmployee extends Employee
{ p
rivate double weeklySalary;
public SalariedEmployee( String n, double salary )
{ super( n );
setWeeklySalary( salary );
}
public void setWeeklySalary( double salary )
{ if ( salary >= 0.0 )
weeklySalary = salary;
else
throw new IllegalArgumentException( "Weekly salary must be >= 0.0" );
}
public double getWeeklySalary()
{ return weeklySalary;
}
@Override
public double earnings()
{ return getWeeklySalary();
}
// end method earnings
@Override
public String toString()
{ return String. format( "salaried employee: %sn%s: $%,.2f",
super.toString(), "weekly salary", getWeeklySalary() );
} // end method toString
} // end class SalariedEmployee
public class PayrollSystemTest
{ public static void main( String[] args )
{ // create subclass objects
SalariedEmployee salariedEmployee = new SalariedEmployee( "Smith", 800.00 );
HourlyEmployee hourlyEmployee = new HourlyEmployee( "Price", 16.75, 40 );
System.out.println( "Employees processed ind ividually:n" );
System.out.printf( "%sn%s: $%,.2fnn",
salariedEmployee, "earned", salariedEmployee.earnings() );
System.out.printf( "%sn%s: $%,.2fnn",hourlyEmployee, "earned", hourlyEmployee.earnings() );
Employee[] employees = new Employee[ 2 ];
employees[ 0 ] = salariedEmployee;
employees[ 1 ] = hourlyEmployee;
for ( Employee currentEmployee : employees )
{ S
ystem.out.println( currentEmployee );
System.out.printf( "earned $%, .2fnn", currentEmployee.earnings() );
} // end for
} // end main
} // end class PayrollSystemTest
請接第五頁
106年公務人員特種考試警察人員一般警察
人員考試及106年特種考試交通事業鐵路
人員、退除役軍人轉任公務人員考試試題 代號:80850 全五頁
第五頁
考試別 鐵路人員考試
等別 員級考試
類科別 資訊處理
科目 程式設計概要
(請接第五頁)
六、說明瀏覽器開啟下列網頁後顯示的訊息與可能的互動。10 分)
<!DOCTYPE html>
<html>
<body>
<p>Creating a JavaScript Object.</p>
<p id="demo"></p>
<p>Show something.</p>
<script>
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
window.alert( person.firstName + " is " + person.age + " years old.");
</script>
</body>
</html>
收藏 ⬇️ 下載