欢迎来到天天文库
浏览记录
ID:40495722
大小:65.50 KB
页数:6页
时间:2019-08-03
《作业5(抽象类作业)含答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.编写程序计算公司的工资单,公司的雇员,执行总裁CEO,委托雇员CommissionedEmployee(其薪水由基本周薪-周内销售的每一项的特定数量来决定)和计件雇员PiecedEmployee(其薪水由他们一周内生产的每件产品的特定数量来决定)组成。提示:定义Employee抽象类,在Employee抽象类中定义计算雇员的抽象方法payment(),CEO,CommissionedEmployee和PiecedEmployee类继承Employee,实现payment()方法。实现全公司发放工资packagec
2、n.com;publicclassCEOextendsEmployee{publicCEO(Stringname){super(name);System.out.println("---有参"+name);}publicCEO(){}publicvoidpayment(){System.out.println(getName()+"工资:10元每小时");}}packagecn.com;publicclassCommissionedEmployeeextendsEmployee{publicCommissionedE
3、mployee(Stringname){super(name);System.out.println("---有参"+name);}publicCommissionedEmployee(){}publicvoidpayment(){System.out.println(getName()+"工资:6元每小时");}}packagecn.com;publicclassPiecedEmployeeextendsEmployee{publicPiecedEmployee(Stringname){super(name);Sy
4、stem.out.println("---有参"+name);}publicPiecedEmployee(){}publicvoidpayment(){System.out.println(getName()+"工资:5元每小时");}}packagecn.com;publicabstractclassEmployee{privateStringname;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}pu
5、blicEmployee(Stringname){this.name=name;}publicEmployee(){}publicabstractvoidpayment();}packagecn.com.test;importcn.com.CEO;importcn.com.CommissionedEmployee;importcn.com.Employee;importcn.com.PiecedEmployee;publicclassTestEmployee{/***@paramargs*/publicstaticv
6、oidmain(String[]args){//TODOAuto-generatedmethodstubEmployeee=newPiecedEmployee("PiecedEmployee");if(einstanceofCEO){CEOceo=(CEO)e;ceo.payment();}elseif(einstanceofCommissionedEmployee){CommissionedEmployeece=(CommissionedEmployee)e;ce.payment();}else{PiecedEmp
7、loyeepe=(PiecedEmployee)e;pe.payment();}}}2抽象类:创建一个Vehicle类并将它声明为抽象类。在Vehicle类中声明一个NoOfWheels方法,使它返回一个字符串值。创建两个类Car和Motorbike从Vehicle类继承,并在这两个类中实现NoOfWheels方法。在Car类中,应当显示“四轮车”信息;而在Motorbike类中,应当显示“双轮车”信息。创建另一个带main方法的类,在该类中创建Car和Motorbike的实例,并在控制台中显示消息。packagec
8、n.comm;publicabstractclassVehicle{privateStringname;publicVehicle(Stringname){this.name=name;}publicVehicle(){}publicStringgetName(){returnname;}publicvoidsetName(Stringname
此文档下载收益归作者所有