1.员工
package bigguy;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public abstract class Employee {
private String name ;
private int number ;
private MyDate birthday ;
public Employee(String name, int number, MyDate birthday) {
this.name = name;
this.number = number;
this.birthday = birthday;
}
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 abstract double earnings( ) ;
@Override
public String toString() {
return "name='" + name + '\'' +
", number=" + number +
", birthday=" + birthday.toDateString() +
'}';
}
}
2.生日
package bigguy;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class MyDate {
private int year ;
private int month ;
private int day ;
public MyDate(int year, int month, int day) {
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 "MyDate{" +
"year=" + year +
", month=" + month +
", day=" + day +
'}';
}
}
3.普通月薪员工
package bigguy;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class SalariedEmployee extends Employee {
private double mothlysalary ;
public SalariedEmployee(String name, int number, MyDate birthday) {
super(name, number, birthday);
}
public SalariedEmployee(String name, int number, MyDate birthday,double mothlysalary) {
super(name, number, birthday);
this.mothlysalary = mothlysalary;
}
public double getMothlysalary() {
return mothlysalary;
}
public double earnings() {
return mothlysalary ;
}
public String toString() {
return "SalariedEmployee{" +super.toString() +"]" ;
}
}
4.小时工
package bigguy;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class HourlyEmployee extends Employee {
private int wage;//每小时工资
private int hour;//一个月工作了多少小时
public HourlyEmployee(String name , int number , MyDate birthday ) {
super( name , number , birthday ) ;
}
public HourlyEmployee(String name , int number , MyDate birthday ,int wage,int hour) {
super( name , number , birthday ) ;
this.wage = wage ;
this.hour = hour ;
}
public int getWage() {
return wage;
}
public void setWage(int wage) {
this.wage = wage;
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = hour;
}
@Override
public double earnings() {
return wage * hour;
}
public String toString() {
return "HourlyEmployee{" + super.toString() + "]";
}
}
5.总薪水(生日+100)
package bigguy;标签:return,name,int,number,birthday,实例,应用,抽象类,public From: https://www.cnblogs.com/liujy2233/p/16819181.html
import java.util.Scanner;
/**
* @author liu$
* @version 1.0
* @description: TODO
* @date $ $
*/
public class PayrollSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in) ;
System.out.println("请输入当月的月份:");
int month = scanner.nextInt() ;
Employee[] emps = new Employee[2] ;
emps[0] = new SalariedEmployee("大嘴盈",1001,new MyDate(2003,9,28),5000) ;
emps[1] = new HourlyEmployee("柳",1002,new MyDate(2003,8,10),240,60) ;
for (int i = 0; i < emps.length; i++) {
System.out.println(emps[i]);
double salary = emps[i].earnings() ;
System.out.println("月工资为:"+salary);
if (month==emps[i].getBirthday().getMonth()){
System.out.println("生日快乐,给你加100块");
}
}
}
}