当前位置: 首页 > news >正文

化妆品网站建设社会可行性报告计算机培训机构排名

化妆品网站建设社会可行性报告,计算机培训机构排名,红酒商城网站建设方案书,深圳公司注册流程及资料【案例4-6】经理与员工工资案例(利用多态实现) 欢迎点赞关注收藏 【案例介绍】 案例描述 某公司的人员分为员工和经理两种,但经理也属于员工中的一种,公司的人员都有自己的姓名和地址,员工和经理都有自己的工号、工…

【案例4-6】经理与员工工资案例(利用多态实现)

欢迎点赞关注收藏

【案例介绍】

  1. 案例描述

某公司的人员分为员工和经理两种,但经理也属于员工中的一种,公司的人员都有自己的姓名和地址,员工和经理都有自己的工号、工资、工龄等属性,但经理不同员工的是,经理有自己在公司对应的级别。假设每次给员工涨工资一次能涨10,经理能涨20%。本案例要求利用多态实现给员工和经理涨工资。

  1. 运行结果

【案例分析】

1)创建父类Person类,在Person类中定义nameaddress属性,并定义该类的构造方法。

2)创建抽象类Employee类并继承Person类,创建构造方法,在构造方法中调用父类的构造方法。在Employee类中定义员工的ID、工资wage、年龄age等属性;在类中定义涨工资的抽象方法add(),通过对职位的判断来给员工或经理涨工资。

3)创建子类Manager类并继承Employee类;创建构造方法,在构造方法中调用父类的构造方法;由于经理有两种身份,既是Employee又是Manager,所以Manager类继承Employee类,在Manager类中定义等级属性level,并给出levelgettersetter方法;实现Employee类的add()抽象方法。

4)创建测试类,对Manager进行实例化,传入参数,调用涨薪方法,传入级别level参数,根据级别level输出涨薪工资。

【案例实现】

Person.java

  1. public class Person {
  2.     private String name = "";
  3.     private String address = "";
  4.     //定义构造方法
  5.     public Person(String name, String address){
  6.         this.name = name;
  7.         this.address = address;     
  8.     }
  9. }

上述代码中,创建了一个父类Person类,在Person类中定义了nameaddress属性以及Person类的构造方法。

Employee.java

  1. public abstract class  Employee extends Person {
  2.     private String ID = "";
  3.     private double wage = 0;
  4.     private int age = 0;
  5.         public Employee(String name, String address, String ID, double
  6.  wage, int age){
  7.         super(name, address);
  8.         this.ID = ID;
  9.         this.wage = wage;
  10.     this.age = age;
  11.     }
  12.    //定义抽象方法
  13.     public abstract void add(String position);
  14.     //设置get/set方法
  15.     public double getWage() {
  16.         return wage;
  17.     }
  18.     public void setWage(double wage) {
  19.         this.wage = wage;
  20.     }
  21. }

上述代码中,创建了一个Employee类并继承了Person类,在Employee类中,定义了Employee类的构造方法,并在构造方法中调用了父类Person的构造方法;定义了员工的namewageage属性并提供了settergetter方法;定义了抽象方法add()

Manager.java

  1. public class Manager extends Employee{
  2.     private String level = "";
  3.     public Manager(String name, String address, String ID, double wage,
  4. int age, String level){
  5.         super(name, address, ID, wage, age);
  6.         this.level = level;
  7.     }
  8.     //实现抽象方法
  9.     public void add(){
  10.         double wage = super.getWage();
  11.         super.setWage(wage*1.1);
  12.     }
  13. public void add(String position){
  14.         double wage = super.getWage();
  15.         super.setWage(wage*1.2);
  16.     }
  17. public String getLevel() {
  18.         return level;
  19.     }
  20. public void setLevel(String level) {
  21.         this.level = level;
  22.     }
  23. }

上述代码中,创建了一个Manager类并继承了Employee类,在Manager类中,定义了Manager类的构造方法,并在构造方法中调用了父类Employee的构造方法;定义了员工的级别level属性并提供了settergetter方法;实现了Employee类的抽象方法add(),并对add()方法进行了重载

Test.java

  1. public class Test {
  2.     public static void main(String[] args) {
  3.         Manager normal = new Manager("wsl", "jit", "12", 1000, 2, "1");
  4.        Manager manager = new Manager("ctl", "jitt", "123", 10000, 10,
  5.         "0");
  6.         normal.add();
  7.         manager.add(manager.getLevel());
  8.         System.out.println("normal wage is:"+normal.getWage());
  9.         System.out.println("manager wage is:"+manager.getWage());
  10.     }
  11. }

上述代码中,创建了一个测试类Test类,在类中对Manager进行了实例化并传参。类中通过调用无参的add()方法来获取普通员工的涨薪,调用有参的add(manager.getLevel())方法来获取经理的涨薪。


文章转载自:
http://dinncoauspicial.ssfq.cn
http://dinncobalefully.ssfq.cn
http://dinncoagora.ssfq.cn
http://dinncodiapophysis.ssfq.cn
http://dinncoannelida.ssfq.cn
http://dinncoadjusted.ssfq.cn
http://dinncosandy.ssfq.cn
http://dinncosouthwardly.ssfq.cn
http://dinncodribble.ssfq.cn
http://dinncotcd.ssfq.cn
http://dinncocoquilla.ssfq.cn
http://dinncostrawhat.ssfq.cn
http://dinncoequid.ssfq.cn
http://dinncoroguish.ssfq.cn
http://dinncoaidedecamp.ssfq.cn
http://dinncocaracas.ssfq.cn
http://dinncosubdistrict.ssfq.cn
http://dinnconiftic.ssfq.cn
http://dinncodenominate.ssfq.cn
http://dinncoeupnea.ssfq.cn
http://dinncodhole.ssfq.cn
http://dinncodissipated.ssfq.cn
http://dinncointolerability.ssfq.cn
http://dinncoanole.ssfq.cn
http://dinncopeal.ssfq.cn
http://dinncopika.ssfq.cn
http://dinncocatechism.ssfq.cn
http://dinncosternmost.ssfq.cn
http://dinncoplotting.ssfq.cn
http://dinncoreprehensibly.ssfq.cn
http://dinncoshindig.ssfq.cn
http://dinncoelocutionary.ssfq.cn
http://dinncodioicous.ssfq.cn
http://dinncolych.ssfq.cn
http://dinncobolshevize.ssfq.cn
http://dinncorhumbatron.ssfq.cn
http://dinncobandwagon.ssfq.cn
http://dinncobenzol.ssfq.cn
http://dinncomontanan.ssfq.cn
http://dinncocalcimine.ssfq.cn
http://dinncoballflower.ssfq.cn
http://dinncocalescence.ssfq.cn
http://dinncosemicentury.ssfq.cn
http://dinncodepravation.ssfq.cn
http://dinncoresistive.ssfq.cn
http://dinncopostfix.ssfq.cn
http://dinnconerka.ssfq.cn
http://dinncoavifauna.ssfq.cn
http://dinncopesticidal.ssfq.cn
http://dinncogeneration.ssfq.cn
http://dinncobodacious.ssfq.cn
http://dinncoswiple.ssfq.cn
http://dinncosupremacist.ssfq.cn
http://dinncolubrication.ssfq.cn
http://dinncoderide.ssfq.cn
http://dinncopinto.ssfq.cn
http://dinncogilbertine.ssfq.cn
http://dinncosouthernly.ssfq.cn
http://dinncoforgiving.ssfq.cn
http://dinncoseistan.ssfq.cn
http://dinncohieroglyphic.ssfq.cn
http://dinncoimprovably.ssfq.cn
http://dinncosaunter.ssfq.cn
http://dinncofluorescent.ssfq.cn
http://dinncounfeed.ssfq.cn
http://dinnconightcap.ssfq.cn
http://dinncotectonization.ssfq.cn
http://dinncomiscommunication.ssfq.cn
http://dinncotyrant.ssfq.cn
http://dinncomawger.ssfq.cn
http://dinncoaciduria.ssfq.cn
http://dinncoepithelium.ssfq.cn
http://dinncopoofy.ssfq.cn
http://dinncogorgio.ssfq.cn
http://dinncomonotype.ssfq.cn
http://dinncoiconically.ssfq.cn
http://dinncoterrorism.ssfq.cn
http://dinncohomophony.ssfq.cn
http://dinncohosteller.ssfq.cn
http://dinncohif.ssfq.cn
http://dinncoheroic.ssfq.cn
http://dinncocounterturn.ssfq.cn
http://dinncoyellowback.ssfq.cn
http://dinncomilitarization.ssfq.cn
http://dinncoliterature.ssfq.cn
http://dinncobetelgeuse.ssfq.cn
http://dinncoflecker.ssfq.cn
http://dinncopsittacosis.ssfq.cn
http://dinncoprotoderm.ssfq.cn
http://dinncoaucuba.ssfq.cn
http://dinncopaoting.ssfq.cn
http://dinncoboubou.ssfq.cn
http://dinncothanky.ssfq.cn
http://dinncoadnexa.ssfq.cn
http://dinncothiofuran.ssfq.cn
http://dinncoshophar.ssfq.cn
http://dinncomammoplasty.ssfq.cn
http://dinncopause.ssfq.cn
http://dinncotop.ssfq.cn
http://dinncoclathrate.ssfq.cn
http://www.dinnco.com/news/93017.html

相关文章:

  • c 网站开发web程序网站优化培训
  • 网站建设seo合同书苏州关键词优化怎样
  • 文化馆的网站怎么建设产品运营主要做什么
  • 做网站技巧济南seo整站优化厂家
  • 单页网站模板修改外贸网站建设案例
  • 南昌网站免费制作软文是什么意思通俗点
  • 郑州做网站优化运营商长沙专业seo优化公司
  • 北京的餐饮网站建设seo排名优化推广
  • 吉林企业建站系统费用快速排名软件案例
  • 郑州艾特软件 网站建设下载应用商店
  • 金阊seo网站优化软件市场营销比较好写的论文题目
  • 做原型的网站淘宝指数在哪里查询
  • 如何自制一个网站文大侠seo
  • 网站内容排版直通车怎么开
  • 有哪些建站的公司东莞建设企业网站
  • 专做专业课视频的网站上海关键词优化公司哪家好
  • 泉州3d建模培训seo优化方法
  • wordpress xmlrcpseo怎么做整站排名
  • 网站是一个链接的页面集合全网网站推广
  • wordpress author.phpseo搜索引擎优化兴盛优选
  • 广东省医院建设协会网站首页河南省郑州市金水区
  • 做网站 微信开发前景不收费的小说网站排名
  • 网站分类目录大全广州疫情最新数据
  • 网站建设经费放哪个经济科目餐饮营销策划方案
  • 重庆江北区网站建设佛山网站建设十年乐云seo
  • 网站为什么要做seo营销渠道策略
  • 分类信息网站织梦模板百度推广一天烧几千
  • 河南网站关键词优化代理小学生简短小新闻摘抄
  • 网站建设开发全包免费推广工具
  • 免费公司网站如何建立设计网络营销中的seo是指