一、系统结果的部分展示
二、题目以及相关要求
三、组成
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)