




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上Java語言課程作業(第二次)題 目 第十六題 學 院 計算機學院 專 業 軟件工程 班 別 14級(2 )班 學 號 姓 名 馮杰俊 2015年11月25日專心-專注-專業一、課程題目 16. 為某公司編寫一個工資支付系統,用于計算某一類員工的月薪。該公司共有四類員工:領固定月薪的(SalariedEmployee),計時取酬的(HourlyEmployee,如果一月工時超過160小時,則還需對額外的工時支付加班費)、按銷售額提成(CommissionEmployee)的和帶底薪并按銷售額提成的(BasePlusCommissionEmployee),其繼承層次結構
2、如下所示。已知每類員工均有表示員工工號、姓名和出生年月的屬性,和用于計算員工月薪的方法。創建一個Employee變量數組,保存Employee類層次結構中每個具體類對象的引用,對每個Employee顯示其工號、姓名、出生年月和月收入,如果當月是Employee的生日所在的月份,則還另發給他100月作為紅包。二、題目分析與設計 1. 題目需求: 計算每一類員工的工資 創建一個Employee變量數組,保存Employee類層次結構中每個具體類對象的引用 對每個Employee顯示其工號、姓名、出生年月和月收入2. 創造一個employee抽象類,其中有employee的基本屬性:工號、姓名、出生
3、年月和月收入,還有一個抽象方法,每一個類員工都是一個具體類,對抽象方法進行不同的重載,以實現不同員工不同的工資計算方法,另外因為本題沒有給出當前月份、固定月薪、銷售每件產品的提成、時薪、加班費等,因此本程序都以假設的方法自行設定,保存在多個接口中,在每個類中按需繼承3. 繼承層次結構EmployeeSalariedEmployeeCommissionEmployeeHourlyEmployeeBasePlusCommissionEmployee4. 開發環境:Eclipse三、測試分析程序輸出:please enter employee type0:SalariedEmployee 1:Hou
4、rlyEmployee 2:CommissionEmployee 3:BasePlusCommissionEmployee用戶輸入:0(這里以固定月薪做示范,假定當前為11月,固定月薪為5000)程序輸出:please enter details of this employee(name number birthyear birthmonth)for example:John9527199510用戶輸入:Jack5816199810name:Jacknumber:5816birthyear:1998birthmonth:10income:5000.please enter employee
5、type0:SalariedEmployee 1:HourlyEmployee 2:CommissionEmployee 3:BasePlusCommissionEmployee用戶輸入:0程序輸出:please enter details of this employee(name number birthyear birthmonth)for example:John9527199510用戶輸入:Jack5816199811(其他不變,月份輸入11)程序輸出:name:Jacknumber:5816birthyear:1998birthmonth:11income:5100.(發了100元
6、紅包)附錄:源代碼import java.util.Scanner; abstract class Employee public int number;public String name=new String10; public int birthYear;public int birthMonth;public static double salary;public abstract void pay(String name,int number,int birthYear,int birthMonth);interface GetMonthpublic int month=11;/假設
7、現在是11月份interface GetSalaryPerMonthpublic double salaryPerMonth=5000;/假設月薪5000元interface GetWorkTimepublic double workTime=250;/假設每個月工作時間200小時public double salaryPerHour=20;/時薪20元public double overTimePay=30;/加班費30元每小時interface GetAmountOfSaledpublic int amountOfSaled=500;/假設一個月銷量500件public double sa
8、laryPerSaled=10;/假設賣一件10元interface GetBasepublic double base=2000;/假設底薪2000元class SalariedEmployee extends Employee implements GetMonth,GetSalaryPerMonthpublic void pay(String name,int number,int birthYear,int birthMonth)if(birthMonth=month) salary=salaryPerMonth+100;/當月為生日月份,則發100元發紅包else salary=sa
9、laryPerMonth;System.out.printf("%sn",name+"%dn",number+"出生年月:%d %dn",birthYear,birthMonth+"月收入:%lfn",salary);class HourlyEmployee extends Employee implements GetMonth,GetWorkTimepublic void pay(String name,int number,int birthYear,int birthMonth)if(workTime>
10、;160) salary=workTime*20+(workTime-160)*30;else salary=workTime*20;if(birthMonth=month) salary+=100;/當月為生日月份,則發100元發紅包System.out.printf("%sn",name+"%dn",number+"出生年月:%d %dn",birthYear,birthMonth+"月收入:%lfn",salary);class CommissionEmployee extends Employee impl
11、ements GetMonth,GetAmountOfSaledpublic void pay(String name,int number,int birthYear,int birthMonth)salary=amountOfSaled*salaryPerSaled;if(birthMonth=month) salary=+100;/當月為生日月份,則發100元發紅包System.out.printf("%sn",name+"%dn",number+"出生年月:%d %dn",birthYear,birthMonth+"
12、月收入:%lfn",salary);class BasePlusCommissionEmployee extends Employee implements GetMonth,GetAmountOfSaled,GetBasepublic void pay(String name,int number,int birthYear,int birthMonth)salary=amountOfSaled*salaryPerSaled+base;if(birthMonth=month) salary=+100;/當月為生日月份,則發100元發紅包System.out.printf("
13、;%sn",name+"%dn",number+"出生年月:%d %dn",birthYear,birthMonth+"月收入:%lfn",salary);public class Paysystem implements GetMonth public static void main(String args)Employee Data=new Employee4;Data0=new SalariedEmployee(); Data1=new HourlyEmployee(); Data2=new CommissionEm
14、ployee(); Data3=new BasePlusCommissionEmployee();/創建一個Employee變量數組,保存Employee類層次結構中每個具體類對象的引用, System.out.println("please enter employee typen0:SalariedEmployee 1:HourlyEmployee 2:CommissionEmployee 3:BasePlusCommissionEmployee"); Scanner s=new Scanner(System.in); int a=s.nextInt(); if(a!=
15、0&&a!=1&&a!=2&&a!=3) System.out.println("error"); System.exit(0); System.out.println("please enter details of this employee(name number birthyear birthmonth)nfor example:nJohnn9527n1995n10"); String str=s.next(); int h=s.nextInt(); int l=s.nextInt(); int m
16、=s.nextInt(); System.out.printf("name:%sn",str); System.out.printf("number:%dnbirthyear:%dnbirthmonth:%dn",h,l,m); switch(a) case(0): if (l=11) System.out.printf("income:%f",SalariedEmployee.salary=5100); else System.out.printf("income:%f",SalariedEmployee.salary=5000); ;break; case(1): if (l=11) System.out.printf("income:%f",SalariedEmployee.salary=6000); else System.out.printf("income:%f",SalariedEmployee.salary=5900); ;break; case(2): if (l=11) System.out.printf("income:%f",SalariedEmployee.salar
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 狗狗褥瘡的護理
- 供熱單位行政工作總結和工作打算
- 車庫認購定金協議書
- 酒店廚房合同協議書
- 龍蝦攤位承包協議書
- 飾品木條轉讓協議書
- 酒店寄存免責協議書
- 包子鋪股份合同協議書
- 道路安全運輸協議書
- 個體戶餐飲股東協議書
- 美容診所合作協議書
- 2025年人教版小學一年級下學期奧林匹克數學競賽試卷(附答案解析)
- 2025年滁州市軌道交通運營有限公司第二批次招聘31人筆試參考題庫附帶答案詳解
- 2025年高考英語考前熱點話題押題卷(新高考Ⅰ卷)-2025年高考英語模擬考試(解析版)
- 浙江國企筆試題目及答案
- 電力現場安全管理課件
- 分子生物學技術在檢驗中的應用試題及答案
- 中考語文專題一非連續性文本閱讀市公開課一等獎市賽課獲獎課件
- 裝維人員銷售培訓
- 改進作風測試題及答案
- 2025年數字療法(Digital+Therapeutics)的市場前景探討
評論
0/150
提交評論