Employee
package 抽象方法练习;
public abstract class Employee {
private String name;
private int number;
private Mydate birthday;
public Employee(String name, int number, Mydate birthday) {
super();
this.name = name;
this.number = number;
this.birthday = birthday;
}
public abstract double earnings();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public Mydate getBirthday() {
return birthday;
}
public void setBirthday(Mydate birthday) {
this.birthday = birthday;
}
public String toString() {
return " 姓名:" + name + " 工号:" + number + " 生日:" + birthday.toDateString();
}
}
Mydate
package 抽象方法练习;
public class Mydate {
private int year;
private int month;
private int day;
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public Mydate(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = day;
}
public String toDateString() {
return year + "年" + month + "月" + day + "日";
}
}
HourlyEmployee
package 抽象方法练习;
public class HourlyEmployee extends Employee {
private double wage;
private int hour;
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
public HourlyEmployee(String name, int number, Mydate birthday,double wage,int hour) {
super(name, number, birthday);
this.hour = hour;
this.wage = wage;
}
public double earnings() {
return wage * hour;
}
public String toString() {
return "类型:HourlyEmployee " + super.toString();
}
}
SalariedEmployee
package 抽象方法练习;
public class SalariedEmployee extends Employee {
private double monthlySalary;
public double getMonthlySalary() {
return monthlySalary;
}
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
public SalariedEmployee(String name, int number, Mydate birthday, double monthlySalary) {
super(name, number, birthday);
this.monthlySalary = monthlySalary;
}
public double earnings() {
return monthlySalary;
}
public String toString() {
return "类型:SalariedEmployee " + super.toString();
}
}
PayrollSystem
package 抽象方法练习;
import java.util.Scanner;
public class PayrollSystem {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入当前月份:");
int m = scan.nextInt();
Employee e[]=new Employee[2];
e[0] = new SalariedEmployee("ljl", 1001, new Mydate(1999, 8, 8), 15000);
e[1] = new HourlyEmployee("wy", 2001, new Mydate(2000, 2, 14), 60, 240);
for(int i = 0; i < e.length;i++) {
System.out.println(e[i].toString());
System.out.println(e[i].getName() + "的月工资为 " +e[i].earnings() );
if(m == e[i].getBirthday().getMonth())
System.out.println(e[i].getName() + "生日快乐,奖励100元");
}
}
}