package com.day28.test;
public abstract class Employee {
private String nameString;
private int number;
private MyDate birthdayDate;
public Employee(String nameString, int number, MyDate birthdayDate) {
super();
this.nameString = nameString;
this.number = number;
this.birthdayDate = birthdayDate;
}
public String getNameString() {
return nameString;
}
public void setNameString(String nameString) {
this.nameString = nameString;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public MyDate getBirthdayDate() {
return birthdayDate;
}
public void setBirthdayDate(MyDate birthdayDate) {
this.birthdayDate = birthdayDate;
}
public abstract double earnings();
@Override
public String toString() {
return "nameString=" + nameString + ", number=" + number + ", birthdayDate=" + birthdayDate.toDateString() ;
}
}
package com.day28.test;
public class MyDate {
private int year;
private int month;
private int day;
public MyDate(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = 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 String toDateString() {
return year+"年"+month+"月"+day+"日";
}
}
package com.day28.test;
public class SalariedEmployee extends Employee {
private double monthSalary;
public SalariedEmployee(String nameString, int number, MyDate birthdayDate) {
super(nameString, number, birthdayDate);
}
public SalariedEmployee(String nameString, int number, MyDate birthdayDate, double monthSalary) {
super(nameString, number, birthdayDate);
this.monthSalary = monthSalary;
}
@Override
public double earnings() {
return monthSalary;
}
public double getMonthSalary() {
return monthSalary;
}
public void setMonthSalary(double monthSalary) {
this.monthSalary = monthSalary;
}
@Override
public String toString() {
return "SalariedEmployee ==>"+super.toString();
}
}
package com.day28.test;
public class HourlyEmployee extends Employee {
private double wage;
private double hour;
public HourlyEmployee(String nameString, int number, MyDate birthdayDate, double wage, double hour) {
super(nameString, number, birthdayDate);
this.wage = wage;
this.hour = hour;
}
public HourlyEmployee(String nameString, int number, MyDate birthdayDate) {
super(nameString, number, birthdayDate);
}
@Override
public double earnings() {
return wage*hour;
}
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
public double getHour() {
return hour;
}
public void setHour(double hour) {
this.hour = hour;
}
@Override
public String toString() {
return "HourlyEmployee ==>"+super.toString();
}
}
package com.day28.test;
import java.util.Calendar;
import java.util.Scanner;
public class PayrollSystem {
public static void main(String[] args) {
Calendar calendar =Calendar.getInstance();
int month=calendar.get(Calendar.MONTH)+1;
System.out.println("当前日期"+month);
Employee[] employee=new Employee[2];
employee[0]=new SalariedEmployee("Json", 1002,new MyDate(2020, 9, 10),12000);
employee[1]=new HourlyEmployee("Whl", 1003, new MyDate(1994, 10, 15),200,8);
for (int i = 0; i < employee.length; i++) {
System.out.println(employee[i]);
double salay= employee[i].earnings();
System.out.println("月工资为"+salay);
if(month == employee[i].getBirthdayDate().getMonth()) {
System.out.println("生日奖励100元!!!");
}
}
}
}