码迷,mamicode.com
首页 > 编程语言 > 详细

使用Java继承的特性实现员工工资管理

时间:2016-08-26 16:56:44      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

父类:

 1 /**
 2  * 员工总类
 3  * @author Administrator
 4  *
 5  */
 6 public class Employee {
 7 
 8     private String name;//员工名字
 9     private int birthMonth;//员工的生日月份
10     public String getName() {
11         return name;
12     }
13     public void setName(String name) {
14         this.name = name;
15     }
16     public int getBirthMonth() {
17         return birthMonth;
18     }
19     public void setBirthMonth(int birthMonth) {
20         this.birthMonth = birthMonth;
21     }
22     
23     /*
24      * 根据参数月份来确定工资,如果该月员工过生日
25      */
26     public double getSalary(int month){
27         return 0;
28     }
29     
30     
31 }

拿固定工资的员工类:

 

 1 /**
 2  * 拿固定工资的员工
 3  * @author Administrator
 4  *
 5  */
 6 public class SalariedEmployee extends Employee {
 7 
 8     private double salary;//月薪
 9 
10     public double getSalary() {
11         return salary;
12     }
13 
14     public void setSalary(double salary) {
15         this.salary = salary;
16     }
17 
18     @Override
19     public double getSalary(int month) {
20         double temp = 0 ;
21         if(this.getBirthMonth() == month){
22             temp += 100;
23         }
24         
25         return temp+salary;
26     }
27     
28     
29     
30 }

 

 按小时拿工资的员工类

 1 /**
 2  * 按小时拿工资的员工
 3  * @author Administrator
 4  *
 5  */
 6 public class HourlyEmployee extends Employee {
 7 
 8     private double hourSalary;//每小时的工资
 9     private double hours;//每月工作的小时数
10     public double getHourSalary() {
11         return hourSalary;
12     }
13     public void setHourSalary(double hourSalary) {
14         this.hourSalary = hourSalary;
15     }
16     public double getHours() {
17         return hours;
18     }
19     public void setHours(double hours) {
20         this.hours = hours;
21     }
22     
23     public double hSalary(){
24         if(hours <= 160){
25             return hours*hourSalary;
26         }else{
27             return 160*hourSalary+(hours-160)*hourSalary*1.5;
28         }
29     }
30     
31     @Override
32     public double getSalary(int month) {
33         double temp = 0 ;
34         if(this.getBirthMonth() == month){
35             temp += 100;
36         }
37         
38         return temp+this.hSalary();
39     }
40     
41 }

 

使用Java继承的特性实现员工工资管理

标签:

原文地址:http://www.cnblogs.com/jpwz/p/5810990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!