2021-07-23
2021/7/24 6:08:23
本文主要是介绍2021-07-23,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
//Employee.java package cn.campsg.java.experiment.entity; public class Employe { private String name; private int level; private int salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public Employe(String name, int level, int salary) { this.name = name; this.level = level; this.salary = salary; } public Employe() { this("1",5,5000); } public void work(){ System.out.println(this.name+"按领导的要求完成任务!"); } }
//Hrstaff.java package cn.campsg.java.experiment.entity; public class Hrstaff extends Employe{ public Hrstaff(){ } public Hrstaff(String name){ super(name,5,5000); } public void work(){ super.work(); System.out.println(this.getName()+" 平时需要组织员工多参加运动。"); } public String looupSalary(int level){ //level=em.getLevel(); if(level>=1&&level<=5){ return "每月补贴500元"; //System.out.println("每月补贴500元"); } else if(level>=6&&level<=9){ return "每月补贴800元"; //System.out.println("每月补贴800元"); } else if(level>=10&&level<=15){ return "每月补贴1000元"; //System.out.println("每月补贴1000元"); } else{ return "不存在对应职级。"; //System.out.println("不存在对应职级。"); } } }
//Company.java package cn.campsg.java.experiment; import cn.campsg.java.experiment.entity.Employe; import cn.campsg.java.experiment.entity.Hrstaff; public class Company extends Hrstaff { public Company(){} public void appraisals(Employe emp){ emp.work(); Hrstaff hr=new Hrstaff(emp.getName()); if(emp.getClass()==hr.getClass()){ hr.setLevel(emp.getLevel()); System.out.println("HR的雇员等级为:"+ hr.getLevel() + "," +hr.looupSalary(hr.getLevel())); } } }
//MainClass.java package cn.campsg.java.experiment; import cn.campsg.java.experiment.entity.Employe; import cn.campsg.java.experiment.entity.Hrstaff; public class MainClass { public static void main(String[] args) { Employe emp=new Employe(); Hrstaff hr=new Hrstaff(); Company com=new Company(); com.appraisals(emp); com.appraisals(hr); } }
这篇关于2021-07-23的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16ShardingSphere 如何完美驾驭分布式事务与 XA 协议?
- 2024-11-16ShardingSphere如何轻松驾驭Seata柔性分布式事务?
- 2024-11-16Maven资料入门指南
- 2024-11-16Maven资料入门教程
- 2024-11-16MyBatis Plus资料:新手入门教程与实践指南
- 2024-11-16MyBatis-Plus资料入门教程:快速上手指南
- 2024-11-16Mybatis资料入门教程:新手必看指南
- 2024-11-16MyBatis资料详解:新手入门与初级实战指南
- 2024-11-16MyBatisPlus资料:初学者入门指南与实用教程
- 2024-11-16MybatisPlus资料详解:初学者入门指南