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

📄 employeetest.java

📁 一些JAVA基础性源代码
💻 JAVA
字号:
package exec.day0918;
/**
 * 写一个程序,把若干各种类型的员工放在一个Employee数组里,写一个函数,
 * 打印出某月每个员工的工资数额。注意:要求把每个类都做成完全封装,不允
 * 许非私有化属性
 * @author Administrator
 *
 */
public class EmployeeTest {
	private Employee e[] = new Employee[4];
	public void init(){
		e[0] = new SalariedEmployee("Narci",7,6000);
		e[1] = new HourlyEmployee("Nancy",12,230,20);
		e[2] = new SalesEmployee("Mary",11,1000000,0.01);
		e[3] = new BasedPlusSalesEmployee("Hillo",9,900000,0.0001,4000);
		
		for(int i=0;i<e.length;i++){
			System.out.println(e[i].getName()+
					"9月份的薪水:"+e[i].getSalary(9));
		}
	}
	public static void main(String[] args) {
		EmployeeTest t = new EmployeeTest();
		t.init();		
	}
}


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{
	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;
	}
}

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{
	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);
	}
}













⌨️ 快捷键说明

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