官术网_书友最值得收藏!

1.3 任務實施

任務 計算員工的月工資

1. 任務需求

某公司分為多個部門,每個部門有一個經(jīng)理和多個員工,每個員工根據(jù)職稱發(fā)基本工資。員工的工資由基本工資、日加班工資、日缺勤工資等組成。具體需求如下所示。

? 員工的基本信息,包括部門、職務、職稱以及工資記錄等信息。

? 能記錄員工的每一個職稱信息,并授予相應的職稱,系統(tǒng)在計算員工工資的時候選取職稱對應的最高職稱津貼。

2. 任務分析

問題域中涉及多個類,包括職員類Staffer、經(jīng)理類Manager、測試類TestEmployee。

? Staffer類:通過此類封裝定義計算職員基本工資方法。

? Manager類:通過此類封裝定義計算經(jīng)理基本工資方法。

? TestEmployee類:調(diào)用方法并實現(xiàn)結果輸出。

其類圖關系如圖1-1所示。

圖1-1 類圖關系

3. 任務實現(xiàn)

package com.daiinfo.seniorjava.ken1.implment; 
/ ** 
 *封裝員工的信息和操作 
 * @author daiyuanquan
 * 
 * / 
public  class Employee { 
    String ID; 
    String name; 
   
    int workdays;//工作天數(shù) 
    int overtimedays;//加班天數(shù) 
    int absencedays;//缺勤天數(shù) 
    double salary;//月工資 
 
    / ** 
     * 構造函數(shù) 
     * / 
    public Employee(String ID) { 
        // TODO Auto-generated constructor stub 
        this.ID=ID; 
    } 
 
    / ** 
     * 構造函數(shù) 
     * / 
    public Employee(String ID,String name) { 
        // TODO Auto-generated constructor stub 
        this.ID=ID; 
        this.name=name; 
    }
    
   
    / ** 
     * 計算員工的工資 
     * @param workdays 工作天數(shù) 
     * @param overtimedays 加班天數(shù) 
     * @param absencedays 缺勤天數(shù) 
     * @return 返回月工資總數(shù) 
     * / 
    double calculateCount(int workdays,int overtimedays,int absencedays){ 
        double count=0.0; 
        count=80.0*workdays+80*overtimedays-30*absencedays; 
        return count; 
    } 
   
    / ** 
     * 轉(zhuǎn)換字符串 
     * / 
    public String toString(){ 
        return name+"\t"+salary; 
    } 
} 
package com.daiinfo.seniorjava.ken1.implment; 
public class Staff extends Employee{ 
    double bassewages=2000; 
    double dailywages=50;//日工資 
    String department; 
    String technicaltitle; 
     
    / ** 
     * 構造函數(shù) 
     * / 
    public Staff(String ID,String name,String department,String technicaltitle)
        super(ID,name); 
        this.department=department; 
        this.technicaltitle=technicaltitle; 
    } 
     
    / ** 
     * 計算員工的工資 
     * @param workdays 工作天數(shù) 
     * @param overtimedays 加班天數(shù) 
     * @param absencedays 缺勤天數(shù) 
     * @return 返回月工資總數(shù) 
     * /
    double calculateCount(int workdays,int overtimedays,int absencedays){ 
        double count=0.0; 
        count=bassewages+dailywages*overtimedays-dailywages*absencedays; 
        return count; 
    } 
      
    / ** 
     * 轉(zhuǎn)換字符串輸出信息 
     * / 
    public String toString(){ 
        return name+"\t"+salary; 
    } 
} 
package com.daiinfo.seniorjava.ken1.implment; 
public class Manager extends Employee { 
    double basewages=3000; 
    String department;//所在部門 
    String positions; 
     
     
    / ** 
     * 構造函數(shù) 
     * @param ID 
     * @param name 
     * @param department 
     * / 
    public Manager(String ID,String name,String department,String positions) { 
        // TODO Auto-generated constructor stub 
        super(ID, name); 
        this.department=department; 
        this.positions=positions; 
         
    } 
     
    / ** 
     * 計算經(jīng)理的工資 
     * @param workdays 工作天數(shù) 
     * @param overtimedays 加班天數(shù) 
     * @param absencedays 缺勤天數(shù) 
     * @return 返回月工資總數(shù) 
     * / 
    double calculateCount(int workdays,int overtimedays,int absencedays){ 
        double count=0.0; 
        count=basewages+20*overtimedays-30*absencedays; 
        return count; 
    } 
} 
package com.daiinfo.seniorjava.ken1.implment; 
/ ** 
 * 測試類的引用 
 *@Copyright: Copyright (c) 2017 
 *@Company: daiinfo 
 * 
 *@author daiyuanquan 
 *@version 1.0 
 *@since 1.0 
 * / 
public class TestEmployee { 
    public static void main(String[] args) { 
        // TODO Auto-generated method stub 
        Manager manager=new Manager("001", "張三", "開發(fā)部","經(jīng)理"); 
        double countsalary=manager.calculateCount(22, 3, 0); 
        System.out.println(countsalary); 
         
        Staff staff=new Staff("2001", "王好", "財務部", "會計師"); 
        double salary=staff.calculateCount(20, 5, 1); 
        System.out.println(salary); 
    } 
} 

運行結果如圖1-2所示。

圖1-2 運行結果

主站蜘蛛池模板: 宁明县| 南溪县| 钟祥市| 和田市| 伊金霍洛旗| 哈尔滨市| 民勤县| 新和县| 太谷县| 年辖:市辖区| 宜章县| 长兴县| 开原市| 尖扎县| 昆明市| 乐山市| 遂昌县| 温州市| 甘谷县| 平果县| 灵宝市| 临城县| 石阡县| 增城市| 山阴县| 东兴市| 琼海市| 额济纳旗| 犍为县| 沙湾县| 秀山| 黑龙江省| 福建省| 徐闻县| 华亭县| 泰和县| 虹口区| 凤山县| 界首市| 永康市| 石景山区|