//Person
public abstract class Person // 人员类,作为基类用
{
private String name;// 姓名
protected String post;// 职位
public Person(String ns, String ps)// 构造方法
{
name = ns;
post = ps;
}
public String getID()// 获取姓名职位信息
{
return (name + " " + post);
}
public abstract double counting();// 计算薪金(抽象方法)
}
//Leader
public class Leader extends Person{
private double 月薪;
public double get月薪() {
return 月薪;
}
public void set月薪(double 月薪) {
this.月薪 = 月薪;
}
public Leader(String ns, String ps) {
super(ns, ps);
// TODO Auto-generated constructor stub
}
public double counting() {
return this.get月薪();
}
}
//Management
public class Management extends Person{
private double 基本工资;
private double 津贴;
public double get基本工资() {
return 基本工资;
}
public void set基本工资(double 基本工资) {
this.基本工资 = 基本工资;
}
public double get津贴() {
return 津贴;
}
public void set津贴(double 津贴) {
this.津贴 = 津贴;
}
public Management(String ns, String ps) {
super(ns, ps);
}
public double counting() {
return this.get基本工资()+this.get津贴();
}
}
//Teacher
public class Teacher extends Person{
private int 职称;
private int 课时;
private double[] 职称等级={0.8,0.9,1.0,1.1,1.2,1.3,1.4};
public int get职称() {
return 职称;
}
public void set职称(int 职称) {
this.职称 = 职称;
}
public Teacher(String ns, String ps) {
super(ns, ps);
}
public double counting() {
return this.get课时()*职称等级[职称]*100;
}
public int get课时() {
return 课时;
}
public void set课时(int 课时) {
this.课时 = 课时;
}
}
//测试类
public class Test {
public static void main(String[] args){
Person no1 = new Leader("张三","老板");
Person no2 = new Management("李四","经理");
Person no3 = new Teacher("王五","英语教师");
((Leader)no1).set月薪(1000);
((Management)no2).set基本工资(1000);
((Management)no2).set津贴(500);
((Teacher)no3).set职称(3);
((Teacher)no3).set课时(24);
System.out.println(no1.counting());
System.out.println(no2.counting());
System.out.println(no3.counting());
}
}