⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeetest.java

📁 基础性的JAVA源代码
💻 JAVA
字号:
package exec.day0927;

public class EmployeeTest {
	private Employee e[] = new Employee[4];
	public void init(){
		e[0] = new SalariedEmployee("胡升平",7,6000);
		e[1] = new HourlyEmployee("刘贤",12,230,20);
		e[2] = new SalesEmployee("李干文",11,1000000,0.01);
		e[3] = new BasedPlusSalesEmployee("林顺达",9,900000,0.0001,4000);
		double addtionalSalary = 0;
		for(int i=0;i<e.length;i++){
			System.out.println(e[i].getName()+
					"9月份的薪水:"+e[i].getSalary(9));
			if(e[i] instanceof AddtionalSalary){
				AddtionalSalary a = (AddtionalSalary)e[i];
				addtionalSalary += a.getAddtionalSalary();
			}
		}
		
	}
	public static void main(String[] args) {
		EmployeeTest t = new EmployeeTest();
		t.init();		
	}
}

interface AddtionalSalary{
	double getAddtionalSalary();
}

class Employee{
	private String name;//姓名
	private int birthMonth;//生日月份
	public Employee(String name,int birthMonth){
		this.name = name;
		this.birthMonth = birthMonth;
	}
	public String getName(){
		return name;
	}
	public double getSalary(int month){
		if(month==birthMonth){
			return 100;
		}
		return 0;
	}
}

class SalariedEmployee extends Employee
				implements AddtionalSalary{
	private double salary;//月薪
	public SalariedEmployee(String name,int birthMonth,double salary){
		super(name,birthMonth);
		this.salary = salary;
	}
	public double getSalary(int month){
		return super.getSalary(month)+salary+
			this.getAddtionalSalary();
	}
	public double getAddtionalSalary(){
		return 2000;
	}
}

class HourlyEmployee extends Employee{
	private double hours;//每月工作的小时数
	private double salaryPerHour;//每小时的工资
	public HourlyEmployee(String name,int birthMonth,
			double hours,double salaryPerHour){
		super(name,birthMonth);
		this.hours = hours;
		this.salaryPerHour = salaryPerHour;
	}
	public double getSalary(int month){
		double result = 0;
		if(hours<=160){
			result = hours*salaryPerHour;
		}else{
			result = 160*salaryPerHour+
			(hours-160)*1.5*salaryPerHour;
		}
		return result+super.getSalary(month);
	}
}

class SalesEmployee extends Employee{
	private double sales;//月销售额
	private double rate;//提成率
	public SalesEmployee(String name,int birthMonth,
			double sales,double rate){
		super(name,birthMonth);
		this.sales = sales;
		this.rate = rate;
	}
	public double getSalary(int month){
		return sales*rate+super.getSalary(month);
	}
}

class BasedPlusSalesEmployee extends SalesEmployee
				implements AddtionalSalary{
	private double basedSalary;//底薪
	public BasedPlusSalesEmployee(String name,int birthMonth,
			double sales,double rate,double basedSalary){
		super(name,birthMonth,sales,rate);
		this.basedSalary = basedSalary;
	}
	public double getSalary(int month){
		return basedSalary+super.getSalary(month)+
					this.getAddtionalSalary();
	}
	public double getAddtionalSalary(){
		return 1000;
	}
}













⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -