员工管理系统(集合与IO流的结合使用 beta1.0 ArrayList<Employee>)
package cn.employee;
public class Employee {
private int empNo;
private String name;
private String department;
public Employee() {
super();
}
public Employee(int empNo, String name, String department) {
super();
this.empNo = empNo;
this.name = name;
this.department = department;
}
public int getEmpNo() {
return empNo;
}
public void setEmpNo(int empNo) {
this.empNo = empNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((department == null) ? 0 : department.hashCode());
result = prime * result + empNo;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
public String toString() {
return "Employee [empNo=" + empNo + ", name=" + name + ", department="
+ department + "]";
}
}
Employee
package cn.employee;
import java.util.List;
public class EmpUtils {
/**
* 是否有相同的员工编号
*/
public static boolean copy(List<Employee> list,int empNo){
boolean flag = false;
for (int i = 0; i < list.size(); i++) {
if(list.get(i).getEmpNo()==empNo){
flag=true;
break;
}
}
return flag;
}
/**
* 添加员工
*/
public static boolean add(List<Employee> list, Employee e) {
if (list.contains(e)) {
System.out.println("有重复的员工");
return false;
}
return list.add(e);
}
/**
* 查询所有员工
*/
public static void querys(List<Employee> list) {
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
/**
* 查询指定员工
*/
public static void query(List<Employee> list,int empNo){
for(int i=0;i<list.size();i++){
if(list.get(i).getEmpNo()==empNo){
System.out.println(list.get(i));
break;
}
if((i==list.size()-1)&&list.get(i).getEmpNo()!=empNo){
System.out.println("不存在该员工!");
}
}
}
/**
* 删除员工
*/
public static void delete(List<Employee> list,int empNo){
for(int i=0;i<list.size();i++){
if(list.get(i).getEmpNo()==empNo){
list.remove(list.get(i));
System.out.println("删除成功!");
break;
}
if((i==list.size()-1)&&list.get(i).getEmpNo()!=empNo){
System.out.println("删除失败!");
}
}
}
/**
* 修改员工
*/
public static void update(List<Employee> list,int empNo,String name,String department){
for (Employee e : list) {
if(e.getEmpNo()==empNo){
e.setName(name);
e.setDepartment(department);
break;
}
}
}
}
EmpUtils
package cn.employee; import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; public class MyEmployee {
Scanner sc = new Scanner(System.in);
List<Employee> list=null;
int empNo;
String name;
String department;
int num = 0;
boolean flag = false; public MyEmployee() { list = new ArrayList<Employee>();
fun(list);
} public void fun(List<Employee> list){ ok: for (;;) {
printOptions();
num = sc.nextInt(); if (num < 1 || num > 6) {
System.out.println("输入有误,将重新开始选择!");
break ok;
} switch (num) {
case 1:
printEmpNo();
if (!EmpUtils.copy(list, empNo)) {
printName();
if (EmpUtils.add(list,new Employee(empNo, name, department))) {
System.out.println("添加成功!");
}
} else {
System.out.println("添加失败!");
}
break;
case 2:
EmpUtils.querys(list);
break;
case 3:
printEmpNo();
EmpUtils.query(list, empNo);
break;
case 4:
printEmpNo();
EmpUtils.delete(list, empNo);
break;
case 5:
printEmpNo();
if (EmpUtils.copy(list, empNo)) {// 有该员工
printName();
EmpUtils.update(list, empNo, name, department);
}
break;
case 6:
flag = true;
} if (flag) {// 退出
break;
}
}
} public void printOptions(){
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("6.退出");
System.out.println("请输入你要进行的操作:");
} public void printEmpNo(){
System.out.println("请输入员工编号:");
empNo = sc.nextInt();
} public void printName(){
System.out.println("请输入员工姓名:");
name = sc.next();
System.out.println("请输入员工部门:");
department = sc.next();
}
}
MyEmployee
package cn.employee;
/**
* 员工管理系统
* @author 王恒
* @time 2016年10月19日 下午8:54:14
*/
public class TestEmp { public static void main(String[] args) { MyEmployee a=new MyEmployee(); }
}
TestEmp
员工管理系统(集合与IO流的结合使用 beta1.0 ArrayList<Employee>)的更多相关文章
- 员工管理系统(集合与IO流的结合使用 beta2.0 ObjectInputStream/ ObjectOutputStream)
package cn.employee; import java.io.Serializable; public class Employee implements Serializable{ pri ...
- 员工管理系统(集合与IO流的结合使用 beta5.0 BufferedReader/ BufferedWriter)
package cn.gee; public class Emp { private String id;//员工编号 一般是唯一的 private String sname; private int ...
- 员工管理系统(集合与IO流的结合使用 beta4.0 ObjectInputStream/ ObjectOutputStream)
package cn.employee_io; import java.io.Serializable; public class Employee implements Serializable{ ...
- 员工管理系统(集合与IO流的结合使用 beta3.0 BufferedReader / ObjectOutputStream)
Employee.java package cn.employee_io; public class Employee { private String empId; private String n ...
- Java集合、IO流、线程知识
一.集合: 1. 集合框架: 1)Collection (1)List:有序的,有索引,元素可重复. (add(index, element).add(index, Collection).remov ...
- Properties集合与IO流
package com.itheima.demo07.Prop; import java.io.FileOutputStream; import java.io.FileReader; import ...
- Io流阶段大总结
字节流结构 输入流: ObjectInputStream:从文件中读取对象 FileInputStream:从文件中输入(读)字节 BufferedInputStream:底层有缓冲数组,在不定义数组 ...
- Java进阶 | IO流核心模块与基本原理
一.IO流与系统 IO技术在JDK中算是极其复杂的模块,其复杂的一个关键原因就是IO操作和系统内核的关联性,另外网络编程,文件管理都依赖IO技术,而且都是编程的难点,想要整体理解IO流,先从Linux ...
- Java基础知识强化之IO流笔记68:Properties和IO流集合使用
1. Properties和IO流集合使用 这里的集合必须是Properties集合: public void load(Reader reader):把文件中的数据读取到集合中 public v ...
随机推荐
- [React] PureComponent in React
In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...
- 碰撞检測之Sphere-Box检測
检測思路 首先要做的是将Box转为AABB,然后推断圆心是否在Box内.用的就是之前的SAT 假设圆心在Box内,肯定相交, 假设不在圆心内.则有四种情况,与顶点相交,与楞相交,与面相交,这里的确定也 ...
- <Android>greenrobot-EventBus,guava-Event Bus的异步实现
刚開始是从otto入手,可是otto不支持异步运行.所以后来才開始研究了Event Bus.关于Event Bus,先前搜索的时候,看到网上的实例,非常碎,并且非常多都是一样的内容,代码看下来基本上是 ...
- C++实现KMP模式匹配算法
#include<iostream> #include<string> #include<vector> using namespace std; void Nex ...
- 《鸟哥的Linux私房菜-基础学习篇(第三版)》(六)
第5章 首次登陆与在线求助man page 1. 首次登陆系统 首先谈了首次登陆CentOS 5.x界面.登陆选项中的会话是能够使用不同的图形界面来操作整个Linux系统. ...
- [IT学习]Python 小项目 通讯录 思路
建立一个通讯录查询软件,暂时只支持按姓名检索.出发点:无需登录企业门户,即可检索.要注意保护员工手机号,除非他自己同意显示. 欢迎您访问www.cnblogs.com/viphhs.转载请联系作者授权 ...
- 2015/12/29 eclipse应用 输出三角形
public class Myfirst { public static void main(String[] args) { System.out.println("hello world ...
- JAVA泛型类
泛型是JDK 5.0后出现新概念,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. 泛型类引入的好处不 ...
- 在Android用ZXing.jar识别二维码的精简版(简化了配置和代码)
近期公司做了一款OTP令牌激活的产品,因为之前激活手机令牌须要输入非常多的激活信息才干进行激活. 经过一段使用后,发现易用性不是非常强,考虑假设添加二维码的的扫码功能岂不是大大添加了易 ...
- UICollectionView基础/UICollectionViewCell的四种创建方式
前言 UICollectionViewCell的四种创建方式:http://blog.csdn.net/ZC_Huang/article/details/52002302 这个控件,看起来与UITab ...