1、假设你又好些个公司,难道每个公司的员工号都不一样吗?
2、使用数组的方式添加员工,当查询的时候,如果员工数量较大,查询和删除等 *** 作比较麻烦。
1)每个员工的信息包括:编号、姓名、性别、出生年月、学历、职务、电话、住址等。(2)系统的功能包括:
(a)查询:按特定条件查找员工。
(b)修改:按编号对某个员工的某项信息进行修改。
(c)插入:加入新员工的信息。
(d)删除:按编号删除已离职员工的信息。
(e)排序:按特定条件对所有员工的信息进行排序。
Employee类:public class Employee {
private int id
private String name
private int age
private String email
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 int getAge() {
return age
}
public void setAge(int age) {
this.age = age
}
public String getEmail() {
return email
}
public void setEmail(String email) {
this.email = email
}
}
Manager类:
import java.util.ArrayList
import java.util.List
public class Manager {
public static List<Employee>employees = new ArrayList<Employee>()
public static void addEmployee(Employee employee){
employees.add(employee)
}
public static void deleteEmployee(Employee employee){
employees.remove(employee)
}
public static void updateEmployee(Employee employee){
int len = employees.size()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getId() == employee.getId()){
deleteEmployee(e)
addEmployee(employee)
}
}
}
public static Employee selectEmployeeById(int id){
int len = employees.size()
if(len!=0){
Employee emp = new Employee()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getId() == id){
emp = e
}
}
return emp
}else{
return null
}
}
public static Employee selectEmployeeByName(String name){
int len = employees.size()
if(len!=0){
Employee emp = new Employee()
for(int i=0i<leni++){
Employee e = employees.get(i)
if(e.getName().equals(name)){
emp = e
}
}
return emp
}else{
return null
}
}
public static void printEmployees(){
int len = employees.size()
if(len != 0){
for(int i=0i<leni++){
System.out.println(employees.get(i).getId()+":\t"+
employees.get(i).getName()+"\t"+
employees.get(i).getAge()+"\t"+
employees.get(i).getEmail())
}
}else{
System.out.println("无员工")
}
}
}
测试EmpManaTest类:
public class EmpManaTest {
public static void main(String[] args) {
Employee e = new Employee()
e.setId(1)
e.setName("zz")
e.setAge(20)
e.setEmail("zz@163.com")
Manager.addEmployee(e)
Employee e2 = new Employee()
e2.setId(2)
e2.setName("scof")
e2.setAge(18)
e2.setEmail("scofield@mail.com")
Manager.addEmployee(e2)
System.out.println("添加员工后:")
Manager.printEmployees()
System.out.println("----------------------------------------------")
Employee emp = new Employee()
emp.setId(1)
emp.setName("virus")
emp.setAge(30)
emp.setEmail("virus@163.com")
Manager.updateEmployee(emp)
System.out.println("修改员工后:")
Manager.printEmployees()
System.out.println("----------------------------------------------")
System.out.println("查询员工ByID:")
Employee empSelectId = Manager.selectEmployeeById(1)
System.out.println(empSelectId.getName())
System.out.println("----------------------------------------------")
System.out.println("查询员工ByName:")
Employee empSelectName = Manager.selectEmployeeByName("virus")
System.out.println(empSelectName.getEmail())
System.out.println("----------------------------------------------")
System.out.println("删除一个员工后:")
Manager.deleteEmployee(emp)
Manager.printEmployees()
}
}
这个是不是你想要的...........
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)