《Java第二次作业第十六题(共11页).doc》由会员分享,可在线阅读,更多相关《Java第二次作业第十六题(共11页).doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
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(workTime160) salary=workTime*20+(workTime-160)*30;else sala
10、ry=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 implements GetMonth,GetAmountOfSaledpublic void pay(String name,int number,int birthYear,int birthMonth)
11、salary=amountOfSaled*salaryPerSaled;if(birthMonth=month) salary=+100;/当月为生日月份,则发100元发红包System.out.printf(%sn,name+%dn,number+出生年月:%d %dn,birthYear,birthMonth+月收入:%lfn,salary);class BasePlusCommissionEmployee extends Employee implements GetMonth,GetAmountOfSaled,GetBasepublic void pay(String name,int
12、 number,int birthYear,int birthMonth)salary=amountOfSaled*salaryPerSaled+base;if(birthMonth=month) salary=+100;/当月为生日月份,则发100元发红包System.out.printf(%sn,name+%dn,number+出生年月:%d %dn,birthYear,birthMonth+月收入:%lfn,salary);public class Paysystem implements GetMonth public static void main(String args)Empl
13、oyee Data=new Employee4;Data0=new SalariedEmployee(); Data1=new HourlyEmployee(); Data2=new CommissionEmployee(); Data3=new BasePlusCommissionEmployee();/创建一个Employee变量数组,保存Employee类层次结构中每个具体类对象的引用, System.out.println(please enter employee typen0:SalariedEmployee 1:HourlyEmployee 2:CommissionEmploye
14、e 3:BasePlusCommissionEmployee); Scanner s=new Scanner(System.in); int a=s.nextInt(); if(a!=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(); in
15、t h=s.nextInt(); int l=s.nextInt(); int m=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=500
16、0); ;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.salary=5100); else System.out.printf(income:%f,SalariedEmployee.salary=5000); ;break; case(3): if (l=11) System.out.printf(income:%f,SalariedEmployee.salary=7100); else System.out.printf(income:%f,SalariedEmployee.salary=7000); ;break;