“人才管理系统” 类描述: 人才信息,属性:姓名,性别,年龄,专业,毕业学校,掌握技能(list集合) 个人简历,继承人才信息,属性:个人简介 猎头公司,属性:公司名称,地址 接口描述: 1、增加人才信息 2、查询人才信息 3、根据年龄向控制台查询人才信息 4、根据专业向控制台查询人才信息 5、查询出技能中掌握java的人才信息 6、猎头公司可以查看人才系统所有人才 7、猎头公司根据选择的人才查看个人的简介 要求: 1、创建三个包,一个包为entity,存放类;一个包为service,存放所有属性接口;一个包为controller,存放测试类 2、增加人才信息时,每个人才信息创建一个文件夹单独存放,文件夹名称为姓名,文件夹内容为个人信息txt和个人介绍txt 3、循环展示人才管理系统的文件夹,通过判断控制台输入内容,查询到相应的人才文件夹,读取文件夹中txt内容,在控制台展示 4、所有输出语句均写在测试类中,方法🈯只做业务操作 5、类名要求按照帕斯卡命名法,首字母大写,其余单词字母均大写,例如:Student(学生类);属性要求按照匈牙利命名法命名,属性名=数据类型+描述,例如strName(姓名),intAge(年龄);方法名要求按照驼峰命名法命名,首字母小写,其余单词首字母大写,例如addStudent(新增学生)
第一次提交
总结:
-
在这里不知道怎么通过文件添加对象里面的list集合这个元素,所以浪费了许多时间,我这次的解决方法是重写toString方法,如何将每一个属性使用","分隔,然后依次为对象赋值 -
第二个问题就是,流的使用还不是非常熟练,尤其是缓冲流的使用,有一点模糊,但是现在清楚了:字节流的缓冲流,不行首先定义字节流,然后通过这个定义的内容传入缓冲流的括号里面;字符流的缓冲流定义也是通过首先定义的字符流,但是这个多了两种方法,那就是FileReader和FileWriter,不过这个和定义字符流的标准方法差不多并且用法大致相同,应该就是为了方便,所以才出现了这两个方法 -
测试类
package controller;
import java.util.Scanner;
import entity.Headhunter;
import entity.Query;
public class Test {
public static void main(String[] args) {
Headhunter hh = new Headhunter("联通公司","东风快递路");
Scanner sc = new Scanner(System.in);
System.out.println("是否增加人才库:1:增加,2:其他");
int c = sc.nextInt();
if(c == 1){
hh.add();
}else if(c == 2){
boolean flag = true;
while(flag){
System.out.println("其他需求:1:按姓名查询,2:按技能查询,3:按年龄查询,4:查询全部,5:退出");
int ch = sc.nextInt();
switch(ch){
case 1:
hh.queryPerForName();
break;
case 2:
hh.queryPerForJava();
break;
case 3:
hh.queryPerForAge();
break;
case 4:
hh.queryP();
break;
case 5:
flag = false;
default:
System.out.println("输入的数据有误!请重新输入!");
}
}
}else{
System.out.println("欢迎使用!");
}
}
}
package entity;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
import org.junit.Test;
import service.QueryImpl;
public class Query implements QueryImpl{
Scanner sc = new Scanner(System.in);
public String path = "E:\\testNomal\\FileTest\\0823";
Map<String, Person> ps1 = new HashMap<String,Person>();
Map<String,Resume> ps2 = new HashMap<String,Resume>();
@Override
public void add(){
FileWriter fw = null;;
BufferedWriter bw = null;
FileWriter fw1 = null;;
BufferedWriter bw1 = null;
List<String> ls = null;
boolean is = true;
int t = 0;
while(is){
System.out.println("请问是否需要添加人才信息?1:是;2:否");
t = sc.nextInt();
if(t == 2){
is = false;
break;
}else{
System.out.println("请输入人才姓名:");
String name = sc.next();
File f = new File(path+"\\"+name);
boolean bf = f.mkdir();
System.out.println(f.getAbsolutePath());
if(bf){
System.out.println("-----请输入个人信息--------");
System.out.print("请输入人才性别:");
String sex = sc.next();
System.out.print("请输入人才年龄:");
int age = sc.nextInt();
System.out.print("请输入人才专业:");
String major = sc.next();
System.out.print("请输入毕业学校:");
String school = sc.next();
boolean flag = true;
int log = 0;
String tecs = null;
ls = new ArrayList<String>();
while(flag){
System.out.print("请输入人才所掌握的技能:");
tecs = sc.next();
ls.add(tecs);
System.out.println("人才是否还有其他技能?1:是;2:无");
log = sc.nextInt();
if(log == 2){
flag = false;
}
}
Person p1 = new Person(name,sex,age,major,school,ls);
ps1.put(name+"个人信息", p1);
System.out.println("---------请输入个人介绍---------");
String pR = sc.next();
Resume r = new Resume(name,sex,age,major,school,ls,pR);
ps2.put(name+"个人介绍", r);
try {
fw = new FileWriter(f.getAbsolutePath()+"\\个人信息.txt");
bw = new BufferedWriter(fw);
fw1 = new FileWriter(f.getAbsolutePath()+"\\个人介绍.txt");
bw1 = new BufferedWriter(fw1);
bw.write(p1.toString());
bw1.write(r.toString());
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw1 != null){
try {
bw1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fw1 != null){
try {
fw1.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(bw != null){
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fw != null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}else{
System.out.println("该人才已经存在!");
}
}
}
}
@Override
public void queryP() {
File fi = new File(path);
File[] lfs = fi.listFiles();
System.out.println("请问是否查看个人信息或者是简历:1:个人信息;2:个人介绍");
int c = sc.nextInt();
for(File fs : lfs){
System.out.println();
if(fs.isDirectory()){
FileReader fr = null;
BufferedReader br = null;
try {
if(c == 1){
fr = new FileReader(fs+"\\"+"个人信息.txt");
br = new BufferedReader(fr,1024);
String i = "";
String msg = "";
while((i=br.readLine()) != null){
msg += i;
}
System.out.println("queryP:"+msg);
}else if(c == 2){
fr = new FileReader(fs+"\\"+"个人介绍.txt");
br = new BufferedReader(fr,1024);
String i = "";
String msg = "";
while((i=br.readLine()) != null){
msg += i;
}
System.out.println("queryR:"+msg);
}else{
System.out.println("输入错误!");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
@Override
public void queryPerForAge() {
File fi = new File(path);
File[] lfs = fi.listFiles();
ArrayList<Person> array = new ArrayList<Person>();
ArrayList<Resume> Rarray = new ArrayList<Resume>();
System.out.println("请问是否查看个人信息或者是简历:1:个人信息;2:个人介绍");
int c = sc.nextInt();
for(File fs : lfs){
if(fs.isDirectory()){
String[] arr0 = {};
FileReader fr = null;
BufferedReader br = null;
try {
if(c == 1){
fr = new FileReader(fs+"\\"+"个人信息.txt");
br = new BufferedReader(fr,1024);
String i = "";
while((i=br.readLine()) != null){
arr0 = i.split(",");
Person p = new Person();
p.setName(arr0[0]);
p.setSex(arr0[1]);
p.setAge(Integer.parseInt(arr0[2]));
p.setMajor(arr0[3]);
p.setSchool(arr0[4]);
ArrayList<String> l = new ArrayList<String>();
for(int j=5;j<arr0.length;j++){
l.add(arr0[j]);
}
array.add(p);
arr0 = null;
}
}else if(c == 2){
fr = new FileReader(fs+"\\"+"个人介绍.txt");
br = new BufferedReader(fr,1024);
String i = "";
while((i=br.readLine()) != null){
String[] arr = i.split(",");
Resume r = new Resume();
r.setpR(arr[0]);
r.setName(arr[1]);
r.setSex(arr[2]);
r.setAge(Integer.parseInt(arr[3]));
r.setMajor(arr[4]);
r.setSchool(arr[5]);
ArrayList<String> lR = new ArrayList<String>();
for(int j=6;j<arr.length;j++){
lR.add(arr[j]);
}
r.setTechs(lR);
Rarray.add(r);
}
}else{
System.out.println("输入错误!");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
System.out.println("请输入你要查询的年龄:");
int ag = sc.nextInt();
if(c == 1){
for(Person pe:array){
if(pe.getAge() == ag){
System.out.println(pe);
}
}
}else if(c == 2){
for(Resume pe:Rarray){
if(pe.getAge() == ag){
System.out.println(pe);
}
}
}else{
System.out.println("输入错误!");
}
}
@Override
public void queryPerForName() {
File fi = new File(path);
File[] lfs = fi.listFiles();
System.out.println("请输入你要查询的姓名:");
String na = sc.next();
ArrayList<Person> array = new ArrayList<Person>();
ArrayList<Resume> Rarray = new ArrayList<Resume>();
System.out.println("请问是否查看个人信息或者是简历:1:个人信息;2:个人介绍");
int c = sc.nextInt();
for(File fs : lfs){
if(fs.isDirectory()){
if(fs.getName().toString().equals(na)){
FileReader fr = null;
BufferedReader br = null;
try {
if(c == 1){
fr = new FileReader(fs+"\\"+"个人介绍.txt");
br = new BufferedReader(fr,1024);
String i = "";
while((i=br.readLine()) != null){
String[] arr = i.split(",");
Person p = new Person();
p.setName(arr[0]);
p.setSex(arr[1]);
p.setAge(Integer.parseInt(arr[2]));
p.setMajor(arr[3]);
p.setSchool(arr[4]);
ArrayList<String> l = new ArrayList<String>();
for(int j=5;j<arr.length;j++){
l.add(arr[j]);
}
p.setTechs(l);
array.add(p);
}
}else if(c == 2){
fr = new FileReader(fs+"\\"+"个人介绍.txt");
br = new BufferedReader(fr,1024);
String i = "";
while((i=br.readLine()) != null){
String[] arr = i.split(",");
Resume r = new Resume();
r.setpR(arr[0]);
r.setName(arr[1]);
r.setSex(arr[2]);
r.setAge(Integer.parseInt(arr[3]));
r.setMajor(arr[4]);
r.setSchool(arr[5]);
ArrayList<String> lR = new ArrayList<String>();
for(int j=6;j<arr.length;j++){
lR.add(arr[j]);
}
r.setTechs(lR);
Rarray.add(r);
}
}else{
System.out.println("输入错误!");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
if(c == 1){
for(Person pe:array){
if(na.equals(pe.getName())){
System.out.println(pe);
}
}
}else if(c == 2){
for(Resume pe:Rarray){
if(na.equals(pe.getName())){
System.out.println(pe);
}
}
}else{
System.out.println("输入错误!");
}
}
@Override
public void queryPerForJava() {
File fi = new File(path);
File[] lfs = fi.listFiles();
ArrayList<Person> array = new ArrayList<Person>();
ArrayList<Resume> Rarray = new ArrayList<Resume>();
System.out.println("请问是否查看个人信息或者是简历:1:个人信息;2:个人介绍");
int c = sc.nextInt();
for(File fs : lfs){
if(fs.isDirectory()){
FileReader fr = null;
BufferedReader br = null;
try {
if(c == 1){
fr = new FileReader(fs+"\\"+"个人信息.txt");
br = new BufferedReader(fr,1024);
String i = "";
ArrayList<String> l = new ArrayList<String>();
while((i=br.readLine()) != null){
String[] arr1 = i.split(",");
Person p = new Person();
p.setName(arr1[0]);
p.setSex(arr1[1]);
p.setAge(Integer.parseInt(arr1[2]));
p.setMajor(arr1[3]);
p.setSchool(arr1[4]);
for(int j=5;j<arr1.length;j++){
l.add(arr1[j]);
}
p.setTechs(l);
array.add(p);
}
}else if(c == 2){
fr = new FileReader(fs+"\\"+"个人介绍.txt");
br = new BufferedReader(fr,1024);
String i = "";
ArrayList<String> lR = new ArrayList<String>();
while((i=br.readLine()) != null){
String[] arr = i.split(",");
Resume r = new Resume();
r.setpR(arr[0]);
r.setName(arr[1]);
r.setSex(arr[2]);
r.setAge(Integer.parseInt(arr[3]));
r.setMajor(arr[4]);
r.setSchool(arr[5]);
for(int j=6;j<arr.length;j++){
lR.add(arr[j]);
}
r.setTechs(lR);
Rarray.add(r);
}
}else{
System.out.println("输入错误!");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(br != null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
System.out.println("请输入人才所需要掌握的技能:");
String t = sc.next();
if(c == 1){
for(Person pe:array){
List<String> techs = pe.getTechs();
if(techs.contains(t)){
System.out.println(pe);
}
}
}else if(c == 2){
for(Resume pe:Rarray){
List<String> techs = pe.getTechs();
if(techs.contains(t)){
System.out.println(pe);
}
}
}else{
System.out.println("输入的信息有错误!");
}
}
}
package entity;
import java.util.List;
public class Person {
private String name;
private String sex;
private int age;
private String major;
private String school;
protected List<String> techs;
public Person() { }
public Person(String name, String sex, int age, String major, String school, List<String> techs) {
super();
this.name = name;
this.sex = sex;
this.age = age;
this.major = major;
this.school = school;
this.techs = techs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public List<String> getTechs() {
return techs;
}
public void setTechs(List<String> techs) {
this.techs = techs;
}
public static String show(List<String> techs){
String sum = techs.get(0);
for(int i=1;i<techs.size();i++){
sum = sum +","+ techs.get(i);
}
return sum;
}
@Override
public String toString() {
return name + "," + sex + "," + age + "," + major + "," + school
+ "," + show(techs) ;
}
}
package service;
public interface QueryImpl {
public abstract void add();
public abstract void queryP();
public abstract void queryPerForAge();
public abstract void queryPerForName();
public abstract void queryPerForJava();
}
package entity;
public class Headhunter extends Query{
private String name;
private String addr;
public Headhunter(String name, String addr) {
super();
this.name = name;
this.addr = addr;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
@Override
public String toString() {
return "Headhunter [name=" + name + ", addr=" + addr + "]";
}
}
package entity;
import java.util.List;
public class Resume extends Person{
private String pR;
public Resume() { }
public Resume(String name, String sex, int age, String major, String school, List<String> techs) {
super(name, sex, age, major, school, techs);
}
public Resume(String name, String sex, int age, String major, String school, List<String> techs, String pR) {
super(name, sex, age, major, school, techs);
this.pR = pR;
}
public String getpR() {
return pR;
}
public void setpR(String pR) {
this.pR = pR;
}
@Override
public String toString() {
return pR + "," + getName() + "," + getSex() + "," + getAge()
+ "," + getMajor() + "," + getSchool() + "," + Person.show(techs);
}
}
|