package cn.lishuailiiuy;
public class start {
public static void main(String[] args) {
System.out.println("------欢迎使用高级人才管理系统-------");
// 调用其它程序完成与控制台的交互过程
new view().core();
System.out.println("------谢谢使用高级人才管理系统-------");
}
}
package cn.lishuailiiuy;
import java.util.Collection;
import java.util.Scanner;
//此类主要显示控制台上的数据,显示客户录入到控制台上的数据
public class view {
public void core() {
while (true) {
System.out.println("请选择你的操作类型:");
System.out.println("A 添加 B 删除 C 修改 D 查询 E 查询所有 F 退出");
// 获取键盘录入
String get = getKeyOf();
get = get.toUpperCase();
switch (get) {
case "A":
addper();
break;
case "B":
break;
case "C":
removeRen();
break;
case "D":
findDanRen();
break;
case "E":
findAllPeople();
break;
case "F":
// 只要选择退出就结束
return;
default:
System.out.println("你输入的选项错误");
}
}
}
private void findDanRen() {
// TODO Auto-generated method stub
System.out.println("请输入你要查询的人的姓名:");
String st = getKeyOf();
fengPople p = jihePeople.getPeople().addDanPeople(st);
if (p == null) {
System.out.println("你查询的人,不存在");
} else {
System.out.println(p);
}
}
private void findAllPeople() {
// TODO Auto-generated method stub
Collection<fengPople> coll = jihePeople.getPeople().addAllPeople();
for (fengPople fengPople : coll) {
System.out.println(fengPople);
}
}
private void removeRen() {
// TODO Auto-generated method stub
System.out.println("请输入要改正人员的名字:");
String st = getKeyOf();
boolean boo = jihePeople.getPeople().xiuRen(st);
if (boo == false) {
System.out.println("你输入的人员名字不存在,请重新输入:");
removeRen();
} else {
// 当返回的是true时就需要重新输入
addper();
}
}
private void addper() {
// TODO Auto-generated method stub
System.out.println("请输入你的姓名:");
String name = getKeyOf();
int age = getAge();
System.out.println("请输入你的性别:");
String nex = getKeyOf();
System.out.println("请输入你的住址:");
String addr = getKeyOf();
System.out.println("请输入你的爱好:");
String good = getKeyOf();
// 到这里客户端录入已经完成,这时需要将这些数据进行封装
fengPople p = new fengPople();
p.setName(name);
p.setAge(age);
p.setAddr(addr);
p.setGood(good);
// 这时将此人的信息添加到一个集合中去
jihePeople.getPeople().addPeople(p);
}
private int getAge() {
// TODO Auto-generated method stub
System.out.println("请输入你的年龄:");
String stage = getKeyOf();
try {
int age = Integer.parseInt(stage);
return age;
} catch (NumberFormatException e) {
System.out.println("你输入的年龄不是纯数字请重新输入");
return getAge();
}
}
public String getKeyOf() {
Scanner sc = new Scanner(System.in);
return sc.nextLine();
}
}
```java
package cn.lishuailiiuy;
public class fengPople {
private String name;
private int age;
private String nex;
private String addr;
private String good;
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 getNex() {
return nex;
}
public void setNex(String nex) {
this.nex = nex;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getGood() {
return good;
}
public void setGood(String good) {
this.good = good;
}
@Override
public String toString() {
return "fengPople [name=" + name + ", age=" + age + ", nex=" + nex + ", addr=" + addr + ", good=" + good + "]";
}
}
```java
package cn.lishuailiiuy;
import java.util.Collection;
import java.util.HashMap;
public class jihePeople {
private jihePeople() {
}
private static final jihePeople jh = new jihePeople();
public static jihePeople getPeople() {
return jh;
}
private final HashMap<String, fengPople> hm = new HashMap<String, fengPople>();
public void addPeople(fengPople p) {
System.out.println(p);
hm.put(p.getName(), p);
}
public boolean xiuRen(String name) {
fengPople p = hm.get(name);
if (p == null) {
return false;
} else {
// 当集合中有这个人时,就将这个人的信息全部删除
return true;
}
}
public Collection<fengPople> addAllPeople() {
// TODO Auto-generated method stub
return hm.values();
}
public fengPople addDanPeople(String name) {
// TODO Auto-generated method stub
return hm.get(name);
}
}