第一篇:某公司的雇员分为以下若干类 Employee这是所有员工总的父类属性员工的姓名和生日月份方法根据月份定工资
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 base = 6000;
private int salary;
public Employee(){
}
public Employee(String name, int month){
this.setName(name);
this.setMonth(month);
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getMonth(){
return month;
}
public void setMonth(int month){
this.month = month;
}
GregorianCalendar g = new GregorianCalendar();
int flag =(int)g.get(Calendar.MONTH)+ 1;
}
public int getSalary(int month){int s = this.getMonth();if(flag == s){salary = base + 100;} elsesalary = base;return salary;} void says(){} System.out.println(“当前月份:” + flag);
// SalaryEmployee:Employee的子类,拿固定工资的员工。属性:月薪
class SalaryEmployee extends Employee {
private int base = 6000;
private int salary;
public SalaryEmployee(String name, int month){
super(name, month);
}
public int getSalary(int month){
int s = this.getMonth();
if(flag == s){
salary = base + 100;
} else {
salary = base;
}
return salary;
}
void says(){
System.out.println(“" + ”姓名:“ + this.getName()+ ”“ + ”生日所在月:“+ this.getMonth()+ ”“ + ”所得薪酬:“ + getSalary(month));
}
}
// HourlyEmployee:Employee的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
// 属性:每小时的工资、每月工作的小时数
private int hours;
private int basehour = 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 setHours(int hours){
this.hours = hours;
}
public int getSalary(int month){
int s = this.getMonth();
if(hours < 160){
if(flag == s){
salary = basehour * hours + 100;
} else
salary = basehour * hours;
} else {
if(flag == s){
salary =(int)(basehour * hours * 1.5)+ 100;
} else
salary =(int)(basehour * hours * 1.5);
}
return salary;
}
void says(){
System.out.println(”“ + ”姓名:“ + this.getName()+ ”“ + ”生日所在月:“+ this.getMonth()+ ”“ + ”所得薪酬:“ + getSalary(month));
}
}
// SalesEmployee:Employee的子类,销售人员,工资由月销售额和提成率决定。属性:月销售额、提成率(sales<60000
// bonus=0.1,sales>=60000 bonus=0.125)
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 setSales(int sales){
this.sales = sales;
}
public int getSalary(int month){
int s = this.getMonth();
if(sales < 60000){
if(s == flag){
salary =(int)(sales * bonus)+ 100;
} else
salary =(int)(sales * bonus);
} else {
if(s == flag){
salary =(int)(sales * bonus * 1.25)+ 100;
} else
salary =(int)(sales * bonus * 1.25);
}
return salary;
}
void says(){
System.out.println(”“ + ”姓名:“ + this.getName()+ ”“ + ”生日所在月:“+ this.getMonth()+ ”“ + ”所得薪酬:“ + getSalary(month));
}
}
// BasePlusSalesEmployee:SalesEmployee的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。属性:底薪。
class BasePlusSalesEmployee extends Employee {
private int sales;
private int base = 3000;
private double bonus = 0.75;
private int salary;
public BasePlusSalesEmployee(String name, int month, int sales){
super(name, month);
this.sales = sales;
}
public int getSales(){
return sales;
}
public void setSales(int sales){
this.sales = sales;
}
public int getSalary(int month){
int s = this.getMonth();
if(sales < 60000){
if(s == flag){
salary =(int)(sales * bonus)+ base + 100;
} else
salary =(int)(sales * bonus)+ base;
} else {
if(s == flag){
salary =(int)(sales * bonus * 1.25)+ base + 100;
} else
salary =(int)(sales * bonus * 1.25)+ base;
}
return salary;
}
void says(){
System.out.println(”“ + ”姓名:“ + this.getName()+ ”“ + ”生日所在月:“+ this.getMonth()+ ”“ + ”所得薪酬:“ + getSalary(month));
}
}
Test.java//测试类
public class Test {
public static void main(String[] args){
Employee e=new Employee(” “,0);
SalaryEmployee se = new SalaryEmployee(”基本工:张三“,8);
HourlyEmployee he = new HourlyEmployee(”小时工:李四“,11, 190);
SalesEmployee sa = new SalesEmployee(”销售额工:王二“,3,79999);
BasePlusSalesEmployee bpse = new BasePlusSalesEmployee(”基本销售额工:于五",7,5000);
e.says();
se.says();
he.says();
sa.says();
bpse.says();
}
}