題組內容
四、某公司的系統必須紀錄員工的姓名(Name)、基本薪水(BaseSalary)及加班費
(OvertimePay),請用 C++、C#、Java 等物件導向程式語言:
⑴定義員工(Employee)類別(class),使其 private 資料成員包含上述員工資料, 且其建構子函式(constructor)的參數即為這三項資料。類別中另含一 public 成 員函式(member function),稱為 TotalPay( ),可計算員工總薪水並 return 之。 (10 分)
詳解 (共 1 筆)
詳解
java版:
public class Employee {
private String Name;
private int BaseSalary;
private int OvertimePay;
Employee(String n, int b, int o) {
this.Name = n;
this.BaseSalary = b;
this.OvertimePay = o;
}public int TotalPay() {
return BaseSalary+OvertimePay;
}
}