题目:某公司的雇员分为以下若干类写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个方法,打印出某月每个员工的工资数额。
注意:要求把每个类都封装,不允许非私有化属性。
Employee:
这是所有员工总的父类,
属性:员工的姓名,员工的生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元。
package zuoye;
//Employee类
public class Employee {
private String name;//名字
private int month;//生日
private double salary;//工资
//构造器
public Employee(){
}
public Employee(String name, int month, double salary) {
this.name = name;
this.month = month;
this.salary = salary;
}
public String getName() {
return name;
}
public int getMonth() {
return month;
}
public double getSalary() {
return salary;
}
public void setName(String name) {
this.name = name;
}
public void setMonth(int month) {
this.month = month;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getSalary(int month){
//判断该月员工是否过生日,过生日则公司会额外奖励100元
if (this.month==month){
salary +=100;
}
System.out.println("员工"+getName()+"的工资为"+salary);
return salary;
}
}
SalariedEmployee:
Employee的子类,拿固定工资的员工。
属性:月薪
package zuoye;
public class SalariedEmployee extends Employee {
private double s1;//月薪
//构造器
public SalariedEmployee() {
}
public SalariedEmployee(double s1) {
this.s1 = s1;
}
public double getS1() {
return s1;
}
public void setS1(double s1) {
this.s1 = s1;
}
public double getSalary(int month) {
//判断该月员工是否过生日,过生日则公司会额外奖励100元
if (this.getMonth() == month) {
s1 += 100;
}
System.out.println("员工" + getName() + "的工资为" + s1);
return s1;
}
}
HourlyEmployee:
Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性:每小时的工资、每月工作的小时数