JAVA 员工管理系统(用抽象类实现),简易版。

2019-05-13 07:20:40来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

 1 package Demo513;
 2 /*
 3 定义一个Employee类,该类包含:
 4         private 成员变量name,number,birthday,其中birthday为MyDate类的对象;
 5         abstract方法earnings():toString()方法输出对象的name,number和birt
 6  */
 7 
 8 public abstract class Employee {
 9     private String name ;
10     private int number ;
11     private MyDate birthday;
12 
13     public String getName() {
14         return name;
15     }
16 
17     public void setName(String name) {
18         this.name = name;
19     }
20 
21     public int getNumber() {
22         return number;
23     }
24 
25     public void setNumber(int number) {
26         this.number = number;
27     }
28 
29     public MyDate getBirthday() {
30         return birthday;
31     }
32 
33     public void setBirthday(MyDate birthday) {
34         this.birthday = birthday;
35     }
36 
37     public Employee(String name, int number, MyDate birthday) {
38         super();
39         this.name = name;
40         this.number = number;
41         this.birthday = birthday;
42     }
43 
44     public abstract double earnings();
45 
46     @Override
47     public String toString() {
48         return "name="+name+",number"+number+",birthday="
49                 +birthday.toString()+"]";
50     }
51 }
 1 package Demo513;
 2 /*
 3 MyDate类包括:
 4         private成员变量month,day,year;
 5         toDateString()方法返回日期对应的字符串:xxxx年xx月xx日
 6  */
 7 public class MyDate {
 8     private int year;
 9     private int month;
10     private int day;
11 
12     public MyDate(int year, int month, int day) {
13         this.year = year;
14         this.month = month;
15         this.day = day;
16     }
17     public String toDateString(){
18         return year + "年"+month+"月"+day+"日";
19     }
20 
21     public int getYear() {
22         return year;
23     }
24 
25     public void setYear(int year) {
26         this.year = year;
27     }
28 
29     public int getMonth() {
30         return month;
31     }
32 
33     public void setMonth(int month) {
34         this.month = month;
35     }
36 
37     public int getDay() {
38         return day;
39     }
40 
41     public void setDay(int day) {
42         this.day = day;
43     }
44 }
 1 package Demo513;
 2 /*
 3 定义 SalariedEmployee类继承Employee类,实现按月计算工资的员工处理。
 4    private成员变量monthlySalary;
 5 实现父类的抽象方法earnings(),该方法返回monthSalary值,toString()方法输出员工类型信息
 6 及员工的name,number,birthday。
 7  */
 8 public class SalariedEmployee extends Employee{
 9     private double monthlySalary;//月工资
10 
11     public SalariedEmployee(String name,int number,MyDate birthdat,double Salary) {
12         super(name,number,birthdat);
13         this.monthlySalary = monthlySalary;
14     }
15 
16     public double earnings(){
17         return monthlySalary;
18     }
19 
20     @Override
21     public String toString() {
22         return "SalariedEmployee{"+super.toString() +
23                 "monthlySalary=" + monthlySalary +
24                 '}';
25     }
26 }
 1 package Demo513;
 2 /*
 3 定义 SalariedEmployee类继承Employee类,实现按月计算工资的员工处理。
 4    private成员变量monthlySalary;
 5 实现父类的抽象方法earnings(),该方法返回monthSalary值,toString()方法输出员工类型信息
 6 及员工的name,number,birthday。
 7  */
 8 public class SalariedEmployee extends Employee{
 9     private double monthlySalary;//月工资
10 
11     public SalariedEmployee(String name,int number,MyDate birthdat,double Salary) {
12         super(name,number,birthdat);
13         this.monthlySalary = monthlySalary;
14     }
15 
16     public double earnings(){
17         return monthlySalary;
18     }
19 
20     @Override
21     public String toString() {
22         return "SalariedEmployee{"+super.toString() +
23                 "monthlySalary=" + monthlySalary +
24                 '}';
25     }
26 }
 1 package Demo513;
 2 /*
 3 定义payrollSystem类,创建Employee变量数组并初始化,该数组存放各类雇员对象的引用。
 4 利用循环结构遍历数组元素。输出各个对象的类型,name,number,birthda,以及对象生日。
 5 当键盘输入本月月份值是,如果本月是某个Employee对象的生日,还要输出增加工资信息。
 6 
 7  */
 8 
 9 import java.util.Scanner;
10 
11 public class PayrollSystem {
12     public static void main(String[] args) {
13         Employee[] emp = new Employee[2];
14         System.out.println();
15         emp[0] = new SalariedEmployee("noo", 1001, new MyDate(2000, 9, 16), 4000);
16         emp[1] = new SalariedEmployee("hjj", 1002, new MyDate(2000, 12, 31), 5000);
17         Scanner scanner=new Scanner(System.in);
18         System.out.println("请输入本月的月份:");
19         int month =scanner.nextInt();
20 
21         for (int i = 0; i < emp.length; i++) {
22             if(month==emp[i].getBirthday().getMonth()){
23                 System.out.println("加工资100");
24             }
25             System.out.println(emp[i]);
26         }
27         
28     }
29 }

 


原文链接:https://www.cnblogs.com/Ssinoo/p/10856286.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:spring中自动装配bean

下一篇:Linux的优缺点,Linux与windows的区别