小白表示试了好久都不能解决这些有关问题= =
小白表示试了好久都不能解决这些问题= =
不好意思,因为这个编码有点长,不过全部的模式几乎都是一样(先constructor,set get method, 然后计算薪水的公式)
其实大家只需要看main class就好了,这些只是用来参考而已(运行的时候Employee, Cleaner, 和Pilot没有错误,可是main class就有)
不好意思,因为这个编码有点长,不过全部的模式几乎都是一样(先constructor,set get method, 然后计算薪水的公式)
其实大家只需要看main class就好了,这些只是用来参考而已(运行的时候Employee, Cleaner, 和Pilot没有错误,可是main class就有)
public class Employee {
private int empNo;
private String empName;
private double basicSalary;
public static int empCount = 0;
//constructor
public Employee() {
}
public Employee(int empNo, String empName, double basicSalary) {
this.empNo = empNo;
this.empName = empName;
this.basicSalary = basicSalary;
}
//set get methods
public void setempNo(int empNo)
{
this.empNo = empNo;
}
public void setempName(String empName)
{
this.empName = empName;
}
public void setbasicSalary(double basicSalary)
{
this.basicSalary = basicSalary;
}
public int getempNo()
{
return this.empNo;
}
public String getempName()
{
return this.empName;
}
public double getbasicSalary()
{
return this.basicSalary;
}
public static int getEmpCount()
{
return empCount;
}
public static void setEmpCount()
{
Employee.empCount+=1;
}
}
public class Pilot extends Employee{
private String level;
private int workingYears;
double monthlyAllowance;
//constuctor
public Pilot()
{
}
public Pilot(int empNo, String empName, double basicSalary, String level, int workingYears)
{
super(empNo, empName, basicSalary);
this.level = level;
this.workingYears = workingYears;
}
//set get method
public void setlevel(String level)
{
this.level = level;
}
public String getlevel()
{
return this.level;
}
public void setworkingYears(int workingYears)
{
this.workingYears = workingYears;
}
public int getworkingYears()
{
return this.workingYears;
}
//method to calculate the salary
public double calculateMonthlyAllowance(String level)
{
if (level.equals("Captain"))
{
monthlyAllowance = 100.00;
}
else if (level.equals("First Officer"))
{
monthlyAllowance = 80.00;
}
else if (level.equals("Second Officer"))
{
monthlyAllowance = 50.00;
}