以java编写员工管理系统(测试过 无问题)

news/2024/11/17 21:24:42/

一、系统结果的部分展示

二、题目以及相关要求

 

 

 三、组成

1.该系统由 Employee 类 、commonEmployee类、Testemd类和managerEmployee类组成

2.Employee实现的代码


public class Employee {private  String id;private  String name;private  String job;private  int holiday;private   int baseSalary;public Employee(String id, String name, String job, int holiday, int baseSalary) {this.id = id;this.name = name;this.job = job;this.holiday = holiday;this.baseSalary = baseSalary;}public Employee() {}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getJob() {return job;}public void setJob(String job) {this.job = job;}public int getHoliday() {return holiday;}public void setHoliday(int holiday) {this.holiday = holiday;}public int getbaseSalary() {return baseSalary;}public void setbaseSalary(int baseSalary) {this.baseSalary = baseSalary;}public double sumCommonEmployeeSalary(int baseSalary,int holiday){ return  baseSalary + baseSalary * 0.1 + baseSalary * 0.5 + 200 -(baseSalary / 20)*holiday  ; }public double sumManagerEmployeeSalary(int baseSalary,int holiday){ return baseSalary + baseSalary*0.2 + baseSalary * 0.5 + 500  - (baseSalary / 20)*holiday;}public String toString(int baseSalary,int holiday,String ids ) {if (ids.equals("员工")) {return "编号为:" + getId() + "    姓名为:" + getName() + "   职务为:" + getJob() + "    请假天数为:" + getHoliday() + "天      " +     getName() + "的薪资为:" + sumCommonEmployeeSalary(getbaseSalary(), getHoliday()) + "元";} else {return "编号为:" + getId() + "    姓名为:" + getName() + "   职务为:" + getJob() + "    请假天数为:" + getHoliday() + " 天      " + getName() + "的薪资为:" + sumManagerEmployeeSalary(getbaseSalary(), getHoliday()) + "元";}}}

3. commonEmployee类的实现:

public class Commonemployee  extends Employee {public Commonemployee(String id, String name, String job, int holiday, int baseSalary) {super(id, name, job, holiday, baseSalary);}public Commonemployee() {}}

4.managerEmployee类的实现:

public class Manageremployee extends Employee{public Manageremployee(String id, String name, String job, int holiday, int baseSalary) {super(id, name, job, holiday, baseSalary);}public Manageremployee() {}}

5.Testemd类的实现:

package chapter03;import java.util.ArrayList;
import java.util.Scanner;public class Testemd {public static void main(String[] args) {Employee e = new Employee();ArrayList<Employee> list = new ArrayList<>();while (true) {System.out.println("|------------------------------------|");System.out.println("|------------- 1. 增加     ---------|");System.out.println("|------------- 2. 删除     ---------|");System.out.println("|------------- 3. 修改     ---------|");System.out.println("|------------- 4. 显示信息     ---|");System.out.println("|------------- 5. 查询       --------|");System.out.println("|------------- 0. 退出     ---------|");System.out.println("|------------------------------------|");System.out.print("请选择业务:");Scanner sc = new Scanner(System.in);int selectChoice = sc.nextInt();switch (selectChoice) {case 1:addEmployee(list);break;case 2:deleteEmployee(list);break;case 3:modEmployee(list);break;case 4:displayEmployee(list);break;case 5:selectEmployee(list);break;case 0:System.out.println("感谢您的使用!");System.exit(0);break;default:System.out.println("您输入的选项有误,请您重新输入!");break;}}}//添加人员public static void addEmployee(ArrayList<Employee> list){Scanner  sc = new Scanner(System.in);String  id ;while (true){System.out.print("请输入职工编号:");id = sc.next();System.out.print("请输入职工的姓名:");String name = sc.next();System.out.print("请输入职工的职务(员工、经理):");String job = sc.next();System.out.print("请输入职工请假天数:");int holiday = sc.nextInt();System.out.print("请输入职工的基本工资:");int  baseSalary = sc.nextInt();if( job.equals("员工")){Commonemployee ce = new Commonemployee();ce.setId(id);ce.setName(name);ce.setHoliday(holiday);ce.setJob(job);ce.setbaseSalary(baseSalary);String info =  ce.toString(baseSalary,holiday,id);System.out.println(info);//将新增加的员工报存到集合中list.add(ce);System.out.println("添加成功!");//测试System.out.println("调用了添加员工的函数");break;}else  if(job.equals("经理")){Manageremployee me = new Manageremployee();me.setId(id);me.setName(name);me.setHoliday(holiday);me.setJob(job);me.setbaseSalary(baseSalary);String info =  me.toString(baseSalary,holiday,id);System.out.println(info);//将新增的员工报存到集合中去list.add(me);System.out.println("添加成功!");//测试System.out.println("调用了添加经理的函数");break;}else {System.out.println(" 您输入的有误!请您输入 员工 / 经理  ");}}}//删除操作public static void deleteEmployee(ArrayList<Employee> list){Scanner sc = new Scanner(System.in);System.out.print("请输入删除的职工号");String id = sc.next();int isExist = -1;for(int i= 0;i < list.size();i++){Employee e = list.get(i);if (e.getId().equals(id)){isExist = i;break;}}if (isExist != -1){list.remove(isExist);System.out.println("删除成功!");System.out.println("被删除的职工号为:"  );}else{System.out.println("输入有误!");}}//修改操作public static void modEmployee(ArrayList<Employee>list){Scanner sc = new Scanner(System.in);System.out.println("请输入修改的职工号:");String id= sc.next();int index = -1;for(int i = 0; i < list.size();++i){Employee e = list.get(i);if (e.getId().equals(id)){index = i;break;}}if (index ==-1){System.out.println("改职工不存在!请重新输入");}else {System.out.print("请输入修改职工工姓名:");String name  = sc.next();System.out.print("请输入修改职工职务(员工/经理):");String job  = sc.next();System.out.print("请输入原职工请假天数:");int  holiday  = sc.nextInt();System.out.print("请输入职工基本工资:");int  baseSalary  = sc.nextInt();if (job.equals("员工")){Commonemployee ce = new Commonemployee();ce.setId(id);ce.setName(name);ce.setHoliday(holiday);ce.setJob(job);ce.setbaseSalary(baseSalary);String info =  ce.toString();list.set(index,ce);System.out.println("修改成功!");}else if(job.equals("经理")){Manageremployee me = new Manageremployee();me.setId(id);me.setName(name);me.setHoliday(holiday);me.setJob(job);me.setbaseSalary(baseSalary);String info =  me.toString();System.out.println(info);list.set(index,me);System.out.println("修改成功!");}}}//显示操作public  static  void displayEmployee(ArrayList<Employee> list ){if(list.size() ==0){System.out.println("当前列表没有任何信息,请输入信息后再操作");}else {for (int i = 0; i  < list.size();++i){Employee e = list.get(i);if(e.getId().equals("员工")){System.out.println("编号为:"+e.getId() +"     姓名为:" + e.getName() + "     职务为:" +e.getJob() + "    假期天数为:"  + e.getHoliday() +" 天     薪资为:" +e.sumCommonEmployeeSalary(e.getbaseSalary(), e.getHoliday())+"元");} else{System.out.println("编号为:"+e.getId() +"     姓名为:" + e.getName() + "     职务为:" +e.getJob() + "    假期天数为:"  + e.getHoliday() +"天      薪资为:" +e.sumManagerEmployeeSalary(e.getbaseSalary(), e.getHoliday())+"元");}}}}//查询操作public static void selectEmployee(ArrayList<Employee>list){while(true) {boolean flag = false;Scanner sc = new Scanner(System.in);if (list.size() == 0) {System.out.println("当前列表没有任何信息,请输入信息后再操作");} else {System.out.print("输入查询的职工号:");String id = sc.next();for (int i = 0; i < list.size(); i++) {Employee e = list.get(i);if (e.getId().equals(id)) {System.out.println(e.toString(e.getbaseSalary(), e.getHoliday(),e.getId()));flag = true;break;}}if (flag==true){break;}System.out.println("输入的编号有错误!请重新输入!");}}}
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                          -------------------------------------------------------------------------------------------                   分割线                  -------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------

 四、Congratulation:

1.首先恭喜你,是一个有进取心的人,想知道事情的底层或者原理

五、详细解释

1.对于Employee类的详解

Employee类前面的基本的JavaBean就不谈了(不知道什么是基本JavaBean去http://www.baidu.com),主要的是在求解不同类的工资时,投了一个小巧,由于commonEmployee类和managerEmployee类均是extends与Employee类的,所以在可以依据输入的职业来判断是员工还是经理,是员工直接调用sumCommonEmoployeeSalary函数否则调用sumManagerEmployeeSalary函数,然后计算相关金额,toString函数很简单就是输出相关信息。

2.对于commonEmployee类和managerEmployee类的详解

太简单了!不讲了

3.对于Testemd类的详解

该类为测试类.................(看不懂的在评论区问,懒得写了)

六、comefrom(cdcas

 


http://www.ppmy.cn/news/31516.html

相关文章

Spring Boot官方例子《Developing Your First Spring Boot Application》无法运行

官方的第一个例子就卡住了&#xff1a; https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started.first-application 按照要求&#xff0c;一步一步走&#xff1a; 查看Java版本和MVN版本&#xff1a; $ java -version openjdk version &quo…

JDBC快速入门

&#x1f34e;道阻且长&#xff0c;行则将至。&#x1f353; 目录 一、JDBC入门 1.概述 (1)JDBC本质 (2)JDBC好处 2.快速入门 (1)步骤 (2)实践 (3)两个小问题 一、JDBC入门 1.概述 JDBC就是使用Java语言操作关系型数据库的一套API&#xff0c;全称&#xff1a;( Java…

QT Q_OBJECT 和 signals/slots

Q_OBJECT宏展开 #define Q_OBJECT \ public: \QT_WARNING_PUSH \Q_OBJECT_NO_OVERRIDE_WARNING \static const QMetaObject staticMetaObject; \virtual const QMetaObject *metaObject() const; \virtual void *qt_metacast(const char *); \virtual int qt_metacall(QMetaOb…

超分扩散模型 SR3 可以做图像去雨、去雾等恢复任务吗?

文章目录前言代码及原文链接主要的点如何进行图像恢复前言 关于扩散模型以及条件扩散模型的介绍&#xff0c;大家可以前往我的上一篇博客&#xff1a;扩散模型diffusion model用于图像恢复任务详细原理 (去雨&#xff0c;去雾等皆可)&#xff0c;附实现代码。 SR3是利用扩散模…

Kafka 消息不丢失

Kafka 消息不丢失生产者丢失消费者丢失不丢失配置Kafka 保证消息不丢失&#xff1a;只对已提交的消息 (committed message) 做有限度的持久化保证 已提交的消息&#xff1a;当 n 个 Broker 成功接收到该消息并写入到日志文件后&#xff0c;就告诉生产者该消息已成功提交有限度…

C++:异常

在学习异常之前&#xff0c;来简单总结一下传统的处理错误的方式&#xff1a; 1. 终止程序&#xff0c;如assert&#xff0c;缺陷&#xff1a;用户难以接受。如发生内存错误&#xff0c;除0错误时就会终止程序。 2. 返回错误码&#xff0c;缺陷&#xff1a;需要程序员自己去查找…

Hadoop小结

Hadoop是什么Hadoop是一 个由Apache基金 会所开发的分布式系统基础架构。主要解决,海量数据的存储和海量数据的分析计算问题。广义上来说&#xff0c;Hadoop通 常是指一个更广泛的概念一Hadoop 生态圈。Hadoop优势Hadoop组成HDFS架构Hadoop Distributed File System&#xff0c…

设计模式——创建型模型——单列模式(8种实现)

前言&#xff1a; &#x1f44f;作者简介&#xff1a;我是笑霸final&#xff0c;一名热爱技术的在校学生。 &#x1f4dd;个人主页&#xff1a;个人主页1 || 笑霸final的主页2 &#x1f4d5;系列专栏&#xff1a;计算机基础专栏 &#x1f4e7;如果文章知识点有错误的地方&#…