java控制台版员工管理系统_java集合的运用:控制台简单员工管理系统

控制台员工管理系统

员工管理系统

==================

【1】增加

【2】删除

【3】修改

【4】查询

【5】浏览

【0】退出

==================

请选择操作:

8bb31daffd5127e85d0d4ef1603f77a2.png

f75de411dfd6a4444e06439350f7b444.png

3fd472fe8a99d5965faba1ca55d4feaa.png

附上代码 :

下面是Employee类:

package com.qikai.Day10终极版员工管理系统;

public class Employee {

private int id;

private String name;

private String address;

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Employee(int id, String name,String address) {

super();

this.id = id;

this.name = name;

this.address=address;

}

@Override

public String toString() {

return "Employee [工号id=" + id + ", 姓名 name=" + name + ",address="+address+"]";

}

}

下面是 方法 实现类:

package com.qikai.Day10终极版员工管理系统;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class T1 {

private static Scanner sc;

public static void main(String[] args) {

showMenu();

Listlist=new ArrayList();//初始化一个学生集合;

while(true){

System.out.print("请选择操作:");

sc=new Scanner(System.in);

String item=sc.nextLine();

switch (item) {

case "1":

add(list); //增加

break;

case "2":

remove(list);

break;

case "3":

update(list); //modify修改

break;

case "4":

select(list);

break;

case "5":

showAll(list);//浏览

break;

case "0":

System.out.println("\t退出成功!");

System.exit(0);

default:

System.out.println("输入错误,请重新选择!");

break;

}

}

}

//查询 方法 ;

private static void select(Listlist) {

System.out.println("\t【查询员工】");

System.out.print("\t请输入待查询工号:");

String id=sc.nextLine();

int index=0;

boolean bool=false;

for (Object object : list) {

Employee emp=(Employee)object;

if(Integer.parseInt(id)==emp.getId()){

index=list.indexOf(emp);

bool=true;

System.out.println("\t请稍候...");

System.out.println("\t"+emp.getId()+"\t"+emp.getName()+"\t"+emp.getAddress());

}

}

if(bool) {

System.out.println("\t查询成功!");

} else{

System.out.println("\t请输入正确的工号:");

}

}

//删除 员工方法 :

private static void remove(Listlist) {

System.out.println("\t【删除员工】");

System.out.print("\t请输入原来工号:");

String oldId=sc.nextLine();

/*//System.out.print(id);

System.out.print("\t请输入原来姓名:");

String oldName=sc.nextLine();

System.out.print("\t请输入原来地址:");

String oldAddress=sc.nextLine();

*/

int index=0;

boolean bool=false;

for (Object object : list) {

Employee emp=(Employee)object;

if(Integer.parseInt(oldId)==emp.getId()){

index=list.indexOf(emp);

bool=true;

}

}

if(bool) {

list.remove(index);

System.out.println("\t删除成功!");

} else{

System.out.println("\t请输入正确的工号:");

}

}

// 浏览员工方法

private static void showAll(Listlist) {

System.out.println("\t工号\t姓名\t地址");

for (Object object : list) {

Employee emp=(Employee)object;

System.out.println("\t"+emp.getId()+"\t"+emp.getName()+"\t"+emp.getAddress());

}

}

// 增加 员工方法 :

private static void add(Listlist) {

System.out.println("\t【增加员工】");

System.out.print("\t请输入工号:");

String id=sc.nextLine();

//System.out.print(id);

System.out.print("\t请输入姓名:");

String name=sc.nextLine();

System.out.print("\t请输入地址:");

String address=sc.nextLine();

list.add(new Employee(Integer.parseInt(id),name,address));//增加

System.out.println("\t增加成功!");

}

// 修改员工 方法

private static void update(Listlist) {

System.out.println("\t【修改员工】");

System.out.print("\t请输入原来工号:");

String oldId=sc.nextLine();

//System.out.print(id);

/*System.out.print("\t请输入原来姓名:");

String oldName=sc.nextLine();

System.out.print("\t请输入原来地址:");

String oldAddress=sc.nextLine();

*/

//int index=list.indexOf(new Employee(Integer.parseInt(oldId),oldName,oldAddress));//同样需要重写equals

int index=0;

boolean bool=false;

for (Object object : list) {

Employee emp=(Employee)object;

if(Integer.parseInt(oldId)==emp.getId()){

index=list.indexOf(emp);

System.out.println("\t请稍候...");

bool=true; // 验证 工号相等就是等。

}

}

if(bool) {

System.out.print("\t请输入新的工号:");

String id=sc.nextLine();

System.out.print("\t请输入新的姓名:");

String name=sc.nextLine();

System.out.print("\t请输入新的地址:");

String address=sc.nextLine();

list.set(index,new Employee(Integer.parseInt(id),name,address));

System.out.println("\t修改成功!");

} else {

System.out.println("\t请输入正确的工号:");

}

}

public static void showMenu() {

System.out.println("员工管理系统");

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("========================");

}

}

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值