员工管理系统

阅读更多
在做的过程中发现自己对集合框架这方面有些不足,下面是集合框架list的应用
package my.employee;

import java.util.ArrayList;
import java.util.Scanner;

public class EmployeeInformationPro {
public  static ArrayList ems=new ArrayList();
public void addEmployee(){
Scanner sc=new Scanner(System.in);
System.out.println("请输入员工编号:");
    String id=sc.nextLine();
    System.out.println("请输入员工姓名:");
    String name=sc.nextLine();
    System.out.println("请输入员工职务:(Employee,Manager,Director)");
    String position=sc.nextLine();
    System.out.println("请输入员工请假天数");
    int holiday=sc.nextInt();
    System.out.println("请输入员工基本工资:");
    double salary=sc.nextDouble();
    if(position.equals("Manager")){
    Employee newOne=new Manager(id,name,position,holiday,salary);
    ems.add(newOne);
    System.out.println("增加数据成功");
    newOne.display();
}else if(position.equals("Employee")){
Employee newOne=new CommonEmployee(id,name,position,holiday,salary);
ems.add(newOne);
    System.out.println("增加数据成功");
    newOne.display();
}else if(position.equals("Director")){
Employee newOne=new Director(id,name,position,holiday,salary);
ems.add(newOne);
    System.out.println("增加数据成功");
    newOne.display();
}else
System.out.println("您输入的职位不存在");
}
public void delEmployee() {
Scanner sc=new Scanner(System.in);
System.out.println("请输入要删除的员工名字");
String name=sc.nextLine();
boolean b1 = false;
for (Employee employee : ems) {
if (employee.getName().equals(name)){
b1 = true;
employee.display();
ems.remove(employee);
System.out.println("删除成功");
break;
}
}
     if (!b1)
System.out.println("您输入的员工不存在");
}

public void queryEmployee() {
Scanner sc=new Scanner(System.in);
System.out.println("请输入要 查询的员工名字");
String name=sc.nextLine();
boolean b1 = false;
for (Employee employee : ems) {
if (employee.getName().equals(name)){
b1 = true;
employee.display();
System.out.println("查询成功");
break;
}
if (!b1)
System.out.println("您输入的员工不存在");
}

}

public void updateEmployee() {
Scanner sc=new Scanner(System.in);
System.out.println("请输入要修改的员工名字");
String name=sc.nextLine();
boolean b1 = false;
for (Employee employee : ems) {
if (employee.getName().equals(name))
System.out.println("请重新输入员工信息");
System.out.println("请输入员工编号:");
    String id=sc.nextLine();
    employee.setID(id);
    System.out.println("请输入员工姓名:");
    String name1=sc.nextLine();
    employee.setName(name1);
    System.out.println("请输入员工职务:(Employee,Manager,Director)");
    String position=sc.nextLine();
    employee.setPosition(position);
    System.out.println("请输入员工请假天数");
    int holiday=sc.nextInt();
    employee.setHoliday(holiday);
    System.out.println("请输入员工基本工资:");
    double salary=sc.nextDouble();
    employee.setSalary(salary);
    employee.display();
}
if (!b1)
System.out.println("您输入的员工不存在");
  }
}






  • StaffManagement.rar (10.3 KB)
  • 下载次数: 0

你可能感兴趣的:(static,ArrayList,Scanner,for)