Employee.ava
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Employee {
/**
* Employee:这是所有员工总的父类,属性:员工的姓名和生日月份。方法:getSalary(int month) 根据参数月份来确定工资,
* 如果该月员工过生日,则公司会额外奖励100元。
*/
private String name;
protected int month;
private int ba = 6000;
private int salary;
public Employee() {
}
public Employee(String name, int month) {
this.tName(name);
this.tMonth(month);
}
public String getName() {
return name;
}
public void tName(String name) {
this.name = name;
}
public int getMonth() {
return month;
}
public void tMonth(int month) {
h = month;
}
GregorianCalendar g = new GregorianCalendar();
int flag = (int) g.get(Calendar.MONTH) + 1;
public int getSalary(int month) {
int s = Month();
if (flag == s) {
salary = ba + 100;
} el
salary = ba;
return salary;
}
void says() {
System.out.println("当前月份:" + flag);
}
}
// SalaryEmployee:Employee的子类,拿固定工资的员工。属性:月薪
class SalaryEmployee extends Employee {
private int ba = 6000;
private int salary;
public SalaryEmployee(String name, int month) {
super(name, month);
}
public int getSalary(int month) {
int s = Month();
if (flag == s) {
salary = ba + 100;
} el {
salary = ba;
}
return salary;
}
void says() {
System.out.println(" " + "姓名:" + Name() + " " + "生日所在月:"
+ Month() + " " + "所得薪酬:" + getSalary(month));
}
}
// HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
// 属性:每小时的工资、每月工作的小时数
class HourlyEmployee extends Employee {
private int hours;
private int bahour = 35;
private int salary;
public HourlyEmployee(String name, int month, int hours) {
super(name, month);
this.hours = hours;
}
public int getHours() {
return hours;
}
public void tHours(int hours) {
this.hours = hours;
}
public int getSalary(int month) {
int s = Month();
if (hours < 160) {
if (flag == s) {
salary = bahour * hours + 100;
} el
salary = bahour * hours;
} el {
if (flag == s) {
salary = (int) (bahour * hours * 1.5) + 100;
} el
salary = (int) (bahour * hours * 1.5);
}
return salary;
}
void says() {
System.out.println(" " + "姓名:" + Name() + " " + "生日所在月:"
+ Month() + " " + "所得薪酬:" + getSalary(month));
}
}
// SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率(sales<60000
// bonus=0.1,sales>=60000 bonus=0.125)
class SalesEmployee extends Employee {
private int sales;
private double bonus = 0.1;
private int salary;
public SalesEmployee(String name, int month, int sales) {
super(name, month);
this.sales = sales;
}
public int getSales() {
return sales;
}
public void tSales(int sales) {
this.sales = sales;
}
public int getSalary(int month) {
int s = Month();
if (sales < 60000) {
if (s == flag) {
salary = (int) (sales * bonus) + 100;
} el
salary = (int) (sales * bonus);
} el {
if (s == flag) {
salary = (int) (sales * bonus * 1.25) + 100;
} el
salary = (int) (sales * bonus * 1.25);
}
return salary;
}
void says() {
System.out.println(" " + "姓名:" + Name() + " " + "生日所在月:"
+ Month() + " " + "所得薪酬:" + getSalary(month));
}
}
// BaPlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。
class BaPlusSalesEmployee extends Employee {
private int sales;
private int ba = 3000;
private double bonus = 0.75;
private int salary;
public BaPlusSalesEmployee(String name, int month, int sales) {
super(name, month);
this.sales = sales;
}
public int getSales() {
return sales;
}
public void tSales(int sales) {
this.sales = sales;
}
public int getSalary(int month) {
int s = Month();
if (sales < 60000) {
if (s == flag) {
salary = (int) (sales * bonus) + ba + 100;
} el
salary = (int) (sales * bonus) + ba;
} el {
if (s == flag) {
salary = (int) (sales * bonus * 1.25) + ba + 100;
} el
salary = (int) (sales * bonus * 1.25) + ba;
}
return salary;
}
void says() {
System.out.println(" " + "姓名:" + Name() + " " + "生日所在月:"
+ Month() + " " + "所得薪酬:" + getSalary(month));
}
}
Test.java//测试类
public class Test {
public static void main(String[] args){
Employee e=new Employee(" ",0);
SalaryEmployee = new SalaryEmployee("基本工:张三",8);
HourlyEmployee he = new HourlyEmployee("小时工:李四",11, 190);
SalesEmployee sa = new SalesEmployee ("销售额工:王二",3,79999);
BaPlusSalesEmployee bp = new BaPlusSalesEmployee("基本销售额工:于五",7,5000);