项目说明
据了解,目前在校大学生80%以上有做兼职的需求,兼职打工已经不仅仅是经济困难的学生赚取生活费用的途径。调查显示,全球经济危机对就业产生冲击,用人单位对人员的社会实践能力要求提高,大学期间必要的社会实践既可以提高能力,又为适应社会,减轻家庭经济负担起到了积极的作用;社会中虚假兼职机构、欺骗性中介机构充斥,真伪难辨,学生受骗事件频发,极大的损害了学生的经济利益,甚至对学生的人生安全造成威胁。从校园踏入社会,兼职只是一段小小的插曲,通过兼职丰富阅历、增长社会经验固然是好事,可是毫无戒备的步入社会,不仅会事与愿违,还可能造成不必要的损所以。所以,我们需求设计一个校园兼职平台来方便在校学生找兼职。
项目内容
项目功能结构图如上图
项目功能:
(1)登录注册功能
用户通过注册进入平台,注册信息包括用户编号(用户编号决定角色类型,学号注册为兼职人员,教师编号注册为管理员)
(2)个人信息管理
包括个人信息修改、密码修改、查询信用等级和查询余额功能
(3)兼职申请功能
包括兼职信息查询、申请工作和结束工作。
(4)基本信息维护功能
包括兼职等级设置、用户信用调整和逾期费用扣除比例调整。
(5)兼职信息投放
包括兼职人员设置、兼职的金额设置、兼职的时间录入以及兼职的其他信息录入。
(6)系统管理功能
包括对普通用户、管理员和兼职信息的增删查改等。
参考设计
结合功能设计,设计5个实体类(或者更多)。
用户实体:用户编号(学号/教师编号)、密码、姓名、年龄、性别、电话、所在院系、注册日期等
兼职信息实体:营业执照编号、公司名字、岗位名称、兼职类型、兼职等级、工作内容、需求人数、工作时间等
兼职类型:兼职类型编号、兼职类型名称、薪水、逾期费用扣除比例
普通用户账户:账户编号、信用等级、余额
具体源码
已完成兼职
package domain;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ApplyJob implements Serializable {
private static final long serialVersionUID = 20L;
private String uid; //用户编号
private String jid; //营业执照编号
private Date work_start; //开始工作时间
private Date work_end; //结束工作时间
private String state = "正在进行"; //兼职状态
private String name; //申请兼职的学生姓名
private String jobName; //申请兼职的岗位名称
private String JTID; //兼职类型标号
public ApplyJob() {
}
public ApplyJob(String uid, String jid, Date work_start, Date work_end) {
this.uid = uid;
this.jid = jid;
this.work_start = work_start;
this.work_end = work_end;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getJid() {
return jid;
}
public void setJid(String jid) {
this.jid = jid;
}
public Date getWork_start() {
return work_start;
}
public void setWork_start(Date work_start) {
this.work_start = work_start;
}
public Date getWork_end() {
return work_end;
}
public void setWork_end(Date work_end) {
this.work_end = work_end;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public String getJTID() {
return JTID;
}
public void setJTID(String JTID) {
this.JTID = JTID;
}
@Override
public String toString() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月dd日");
String data1 = sdf.format(work_start);
String data2 = sdf.format(work_end);
return "ApplyJob{" +
"接此兼职的用户学号='" + uid + '\'' +
", 申请此兼职的用户姓名='" + name + '\'' +
", 该兼职的公司营业编号=" + jid + '\'' +
", 该兼职的兼职类型编号=" + JTID + '\'' +
", 该兼职的岗位名称='" + jobName + '\'' +
", 开始时间='" + data1 + '\'' +
", 结束时间='" + data2 + '\'' +
", 兼职状态='" + state + '\'' +
'}';
}
}
兼职
package domain;
import java.io.Serializable;
public class Job implements Serializable {
private static final long serialVersionUID = 30L;
private String JID;//营业执照编号
private String company_name;//公司名字
private String job_name;//岗位名称
private String job_level;//兼职等级
private String job_content;工作内容
private int job_demand;//需求人数
private String job_time;//工作时间
private JobType jobType = new JobType();//兼职类型
public Job() {
}
public Job(String JID, String company_name, String job_name, String job_level, String job_content, int job_demand, String job_time, JobType jobType) {
this.JID = JID;
this.company_name = company_name;
this.job_name = job_name;
this.job_level = job_level;
this.job_content = job_content;
this.job_demand = job_demand;
this.job_time = job_time;
this.jobType = jobType;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getJID() {
return JID;
}
public void setJID(String JID) {
this.JID = JID;
}
public String getCompany_name() {
return company_name;
}
public void setCompany_name(String company_name) {
this.company_name = company_name;
}
public String getJob_name() {
return job_name;
}
public void setJob_name(String job_name) {
this.job_name = job_name;
}
public String getJob_level() {
return job_level;
}
public void setJob_level(String job_level) {
this.job_level = job_level;
}
public String getJob_content() {
return job_content;
}
public void setJob_content(String job_content) {
this.job_content = job_content;
}
public int getJob_demand() {
return job_demand;
}
public void setJob_demand(int job_demand) {
this.job_demand = job_demand;
}
public String getJob_time() {
return job_time;
}
public void setJob_time(String job_time) {
this.job_time = job_time;
}
public JobType getJobType() {
return jobType;
}
public void setJobType(JobType jobType) {
this.jobType = jobType;
}
@Override
public String toString() {
return "* 营业执照编号=" + JID + '\n' +
"* 公司名称=" + company_name + '\n' +
"* 岗位名称=" + job_name + '\n' +
"* 兼职等级=" + job_level + '\n' +
"* 工作内容=" + job_content + '\n' +
"* 需求人数=" + job_demand + '\n' +
"* 工作时间=" + job_time + '\n' +
"* 兼职类型\t" + jobType;
}
}
兼职类型
package domain;
import java.io.Serializable;
public class JobType implements Serializable {
//兼职类型
private static final long serialVersionUID = 40L;
private String JTID;//兼职类型标号
private double salary;//薪水
private double deduct_salary;//逾期后薪水口粗比例
private String jobtype_name;//兼职类型名称
public String getJTID() {
return JTID;
}
public void setJTID(String JTID) {
this.JTID = JTID;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getDeduct_salary() {
return deduct_salary;
}
public void setDeduct_salary(double deduct_salary) {
this.deduct_salary = deduct_salary;
}
public String getJobtype_name() {
return jobtype_name;
}
public void setJobtype_name(String jobtype_name) {
this.jobtype_name = jobtype_name;
}
@Override
public String toString() {
return "* 兼职类型编号=" + JTID + '\t' +
"* 兼职类型名称=" + jobtype_name + '\t' +
"* 薪水=" + salary + '\t' +
"* 逾期费用扣除比例=" + deduct_salary * 100 + "%";
}
}
角色
package domain;
import java.io.Serializable;
public class Role implements Serializable {
//角色,能不能登录注册的名单的类,可以通过方法来修改那个userMessage.txt文件
private static final long serialVersionUID = 50L;
private String UID;
private String name;
public Role() {
}
public Role(String UID, String name) {
this.UID = UID;
this.name = name;
}
public String getUID() {
return UID;
}
public void setUID(String UID) {
this.UID = UID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
用户
package domain;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
//注册日期用的时候再看情况要不要转为字符串
private static final long serialVersionUID = 60L;
private String UID;//学号或者老是编号
private String password;
private String userName;//姓名
private int age = 0;//年龄
private String sex = "未知";//性别
private String phone = "未知";//电话号码
private String department = "未知";//部门,所在院系
private Date regdat = null;//注册时间
private int increase = 0;//用于判断是否能提高信用等级的
private UserAccount userAccount; //普通用户账户
public User(String UID, String password, String userName) {
this.UID = UID;
this.password = password;
this.userName = userName;
regdat = new Date();
userAccount=new UserAccount();
userAccount.setACID(UID);
}
public String getUID() {
return UID;
}
public void setUID(String UID) {
this.UID = UID;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public Date getRegdat() {
return regdat;
}
public void setRegdat(Date regdat) {
this.regdat = regdat;
}
public int getIncrease() {
return increase;
}
public void setIncrease(int increase) {
this.increase = increase;
}
public UserAccount getUserAccount() {
return userAccount;
}
public void setUserAccount(UserAccount userAccount) {
this.userAccount = userAccount;
}
@Override
public String toString() {
return "domain.User{" +
"UID='" + UID + '\'' +
", password='" + password + '\'' +
", userName='" + userName + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", phone='" + phone + '\'' +
", department='" + department + '\'' +
", regdat=" + regdat +
", increase=" + increase +
", userAccount=" + userAccount +
'}';
}
}
用户账户
package domain;
import java.io.Serializable;
public class UserAccount implements Serializable {
private static final long serialVersionUID = 70L;
private String ACID;//账户编号
private int credit_rating = 5;//信用等级
private double balance;//余额
public UserAccount() {
}
public UserAccount(String ACID, int credit_rating, double balance) {
this.ACID = ACID;
this.credit_rating = credit_rating;
this.balance = balance;
}
public String getACID() {
return ACID;
}
public void setACID(String ACID) {
this.ACID = ACID;
}
public int getCredit_rating() {
return credit_rating;
}
public void setCredit_rating(int credit_rating) {
this.credit_rating = credit_rating;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
@Override
public String toString() {
return "domain.UserAccount{" +
"ACID='" + ACID + '\'' +
", credit_rating=" + credit_rating +
", balance=" + balance +
'}';
}
}
兼职信息录入
package service;
import domain.Job;
import domain.JobType;
import view.IOUtility;
import view.TSUtility;
import java.io.IOException;
import java.util.ArrayList;
public class InformationDelivery {
public static void jobInput() {
//兼职信息录入(创建兼职)
//营业执照编号='null', 公司名称='null',
// 岗位名称='null', 兼职等级='null',
// 工作内容='null', 需求人数=0',
// 工作时间='null', 兼职类型=兼职类型编号='null',
// 兼职类型名称=null', 薪水=0.0', 逾期费用扣除比例='0.0%
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
Job njob = new Job();
JobType jobType = njob.getJobType();
System.out.println("!!**欢迎来到兼职投放界面**!!");
System.out.println("请输入兼职营业执照编号");
String JID = TSUtility.readKeyBoard(10, false);
njob.setJID(JID);
System.out.println("请输入该兼职的公司名字");
String company_name = TSUtility.readKeyBoard(10, false);
njob.setCompany_name(company_name);
System.out.println("请输入该兼职的岗位名称");
String job_name = TSUtility.readKeyBoard(10, false);
njob.setJob_name(job_name);
System.out.println("请输入兼职等级(1-5)");
// String job_level = TSUtility.readKeyBoard(1, false);
njob.setJob_level(TSUtility.readlevel());
System.out.println("请输入工作内容");
String job_content = TSUtility.readKeyBoard(100, false);
njob.setJob_content(job_content);
System.out.println("请输入需求人数");
int job_demand = TSUtility.readInt();
njob.setJob_demand(job_demand);
System.out.println("请输入工作时间(注意:输入格式为”yyyy-MM-dd到yyyy-MM-dd“):");
String time = TSUtility.readJobTime();
njob.setJob_time(time);
//输入兼职类型
boolean flag;
do {
System.out.println("请输入兼职类型编号");
String JTID = TSUtility.readKeyBoard(4, false);
flag = true;
for (Job job1 : list) {
if (job1.getJID().equals(JID) && job1.getJobType().getJTID().equals(JTID)) {
System.out.println("该兼职类型编号已经被本公司其他兼职占用,请重新输入兼职类型编号:");
flag = false;
break;
}
}
if (flag)
jobType.setJTID(JTID);
} while (!flag);
System.out.println("请输入兼职类型名称:");
jobType.setJobtype_name(TSUtility.readKeyBoard(4, false));
System.out.println("请输入薪水:");
jobType.setSalary(TSUtility.readDouble());
System.out.println("请输入逾期费用扣除比例:(比如要输入25%,你只需要输入25即可)");
jobType.setDeduct_salary(Integer.parseInt(TSUtility.readKeyBoard(2, false)) / 100.0);
list.add(njob);
try {
IOUtility.writeJob(list);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("兼职投放成功!!!!程序将自动返回!");
try {
TSUtility.loadSpecialEffects();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
管理员基本信息维护界面的功能
package service;
import domain.Job;
import domain.JobType;
import domain.User;
import domain.UserAccount;
import view.IOUtility;
import view.PrintUtility;
import view.TSUtility;
import java.io.IOException;
import java.util.ArrayList;
import static view.IOUtility.readUser;
import static view.PrintUtility.printWithColor;
public class InformationMaintenance {
//管理员基本信息维护界面的功能
public static void jobLevelSet() {
//兼职等级设置
while (true) {
ArrayList<Job> joblist = null;
try {
joblist = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (joblist == null || joblist.isEmpty() || joblist.size() == 0) {
System.out.println("还没有投放工作,无法修改");
return;
}
printWithColor("紫红色", "请输入想要修改的兼职等级的JID");
String JID = TSUtility.readKeyBoard(10, false);
printWithColor("紫红色", "请输入想要修改的兼职的JTID");
String JTID = TSUtility.readKeyBoard(10, false);
for (Job job : joblist) {
if (job.getJID().equals(JID)) {
if (job.getJobType().getJTID().equals(JTID)) {
printWithColor("紫红色", "您想要修改的兼职" + JID + "\n" +
"当前兼职等级为" + job.getJob_level());
printWithColor("紫红色", "请输入调整后的等级(1-5)");
String level = TSUtility.readlevel();
job.setJob_level(level);
try {
IOUtility.writeJob(joblist);
} catch (IOException e) {
e.printStackTrace();
}
printWithColor("绿色", "修改成功,将自动返回上级菜单");
return;
}
}
}
System.out.println("对不起,您想要进行修改的兼职不存在");
System.out.println("修改失败,请输入正确JID");
continue;
}
}
public static void jobTypeSet() {
//兼职类型设置
while (true) {
ArrayList<Job> joblist = null;
try {
joblist = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (joblist == null || joblist.isEmpty()) {
System.out.println("还没有投放职位,无法修改");
return;
}
printWithColor("紫红色", "请输入想要修改的兼职类型的JID");
String JID = TSUtility.readKeyBoard(10, false);
printWithColor("紫红色", "请输入想要修改的兼职的JTID");
String JTID = TSUtility.readKeyBoard(10, false);
for (Job job : joblist) {
if (job.getJID().equals(JID)) {
if (job.getJobType().getJTID().equals(JTID)) {
printWithColor("绿色", "当前兼职类型如下\n" +
job.getJobType());
JobType nJobType = new JobType();
nJobType.setJTID(JTID);
printWithColor("绿色", "请输入修改的信息(不想修改的回车跳过)");
printWithColor("绿色", "请输入想要修改的兼职类型名称(不想修改的回车跳过)");
nJobType.setJobtype_name(TSUtility.readJobtype_name(job.getJobType().getJobtype_name()));
printWithColor("绿色", "请输入想要修改的薪水(不想修改的回车跳过)");
nJobType.setSalary(TSUtility.readSalary(job.getJobType().getSalary()));
printWithColor("绿色", "请输入逾期费用扣除比例:" +
"(比如要输入25%,你只需要输入25即可)" +
"(不想修改的回车跳过)");
nJobType.setDeduct_salary(TSUtility.readDeduct_salary(job.getJobType().getDeduct_salary()) / 100);
job.setJobType(nJobType);
try {
IOUtility.writeJob(joblist);
} catch (IOException e) {
e.printStackTrace();
}
printWithColor("绿色", "修改成功,将自动返回上级菜单");
return;
}
}
}
System.out.println("对不起,您想要进行修改的兼职不存在");
System.out.println("修改失败,请输入正确JID");
continue;
}
}
public static void userCredit_ratingSet() {
//用户信用调整
PrintUtility.printWithColor("黄色", "请输入想要调整用户信用的用户UID");
String UID = TSUtility.readKeyBoard(10, false);
User user = null;
try {
user = readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (user == null) {
System.out.println("没有该用户,即将返回上级菜单");
return;
}
if (user.getUserAccount() == null) {
System.out.println("该用户没有账户,请先给他添加一个");
return;
}
System.out.println("当前信用等级为:");
int ratingNum = user.getUserAccount().getCredit_rating();
System.out.println(ratingNum);
if (ratingNum < 1) {
System.out.println("对不起,该用户信用等级过低,无法调整,即将自动返回上级菜单");
try {
TSUtility.loadSpecialEffects();
} catch (InterruptedException e) {
e.printStackTrace();
}
return;
}
UserAccount userAccount = new UserAccount();
userAccount.setACID(user.getUserAccount().getACID());
userAccount.setBalance(user.getUserAccount().getBalance());
PrintUtility.printWithColor("黄色", "请输入想要将信用等级调整到的等级(1-5)");
int newRating = TSUtility.readFive();
userAccount.setCredit_rating(newRating);
PrintUtility.printWithColor("黄色", "修改成功,即将自动跳转到上级菜单");
return;
}
}
管理员的模块
package service;
import domain.ApplyJob;
import domain.Job;
import domain.User;
import domain.UserAccount;
import view.IOUtility;
import view.PrintUtility;
import view.TSUtility;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class SystemAdministration {
//管理员的模块
public static void delModule() {
//删除账户、删除用户、兼职信息删除
while (true) {
PrintUtility.printdelModule();
char choose = TSUtility.readForth();
switch (choose) {
case '1':
//删除账户
delAccount();
break;
case '2':
//删除用户
delUser();
break;
case '3':
//兼职信息删除
delJob();
break;
case '4':
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
public static void addModule() {
//添加用户、添加账户、修改账户密码
while (true) {
PrintUtility.printAddModuleMenu();
char choose = TSUtility.readForth();
switch (choose) {
case '1':
//添加用户
addRole();
break;
case '2':
//添加账户
addAccount();
break;
case '3':
//修改账户密码
changePassword();
break;
case '4':
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
public static void inquireModule() {
//查询模块
while (true) {
PrintUtility.printInquireModule();
char choose = TSUtility.readSix();
switch (choose) {
case '1':
//查询用户
inquireUser();
break;
case '2':
//查询账户
inquireUserAccount();
break;
case '3':
//查询已投放职位
inquireJob();
break;
case '4':
//查询已完成职位
inquireApplyJob();
break;
case '5':
//查询逾期兼职信息
inquireLateApplyJob();
break;
case '6':
//返回上级菜单
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
private static void inquireLateApplyJob() {
//查询逾期兼职信息
ArrayList<ApplyJob> applyJobs = null;
try {
applyJobs = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (applyJobs.isEmpty()) {
System.out.println("还没有兼职被申请");
return;
}
ArrayList<Job> jobs = null;
try {
jobs = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (jobs.isEmpty()) {
System.out.println("没有兼职");
return;
}
System.out.println("逾期的兼职为");
for (ApplyJob applyJob : applyJobs) {
if (applyJob.getState().equals("逾期完成")) {
for (Job job : jobs) {
if (job.getJID().equals(applyJob.getJid()) && job.getJobType().getJTID().equals(applyJob.getJTID())) {
System.out.println(job + "状态是" + applyJob.getState());
}
}
}
}
}
private static void inquireApplyJob() {
//管理员查询已完成职位
ArrayList<ApplyJob> applyJobs = null;
try {
applyJobs = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (applyJobs.isEmpty() || applyJobs.size() == 0 || applyJobs == null) {
System.out.println("还没有兼职被申请");
return;
}
ArrayList<Job> jobs = null;
try {
jobs = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (jobs.isEmpty() || jobs.size() == 0 || jobs == null) {
System.out.println("没有兼职");
return;
}
System.out.println("已经完成了的兼职如下:");
for (ApplyJob applyJob : applyJobs) {
if (applyJob.getState().equals("逾期完成") || applyJob.getState().equals("已按时完成")) {
//已经完成了的兼职被找到了
for (Job job : jobs) {
if (job.getJID().equals(applyJob.getJid()) && job.getJobType().getJTID().equals(applyJob.getJTID())) {
System.out.println(job +"是"+ applyJob.getName() + applyJob.getState()+"的");
}
}
System.out.println("------------");
}
}
}
public static void addRole() {
//添加可注册人员
String sname = "E:\\Campus_Part_time\\src\\view\\userList.txt";
System.out.println("请输入要添加的人员的UID(s开头为学生,t开头为管理员)");
String roUID = TSUtility.readKeyBoard(10, false);
System.out.println("请输入要添加的人员的姓名");
String roName = TSUtility.readKeyBoard(10, false);
String role = roUID + "=" + roName;
ArrayList<String> arrayList = new ArrayList<>();
try {
arrayList = IOUtility.getRole(sname);//从文件中获取角色,存入集合之中
} catch (IOException e) {
e.printStackTrace();
}
boolean fl = true;
for (String s : arrayList) {//遍历集合
s = s.toLowerCase();//将学号变成小写
if (s.equals(role)) {//判断是否重复
System.out.println("添加的人员已经存在");
fl = false;
break;
}
int s2 = s.indexOf("=");
if (s2 != -1) {
String s3 = s.substring(0, s2);
if (s3.equals(roUID)) {
System.out.println("添加的人员已经存在");
fl = false;
break;
}
}
}
if (fl) {//不重复的话就存入集合之中
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(sname));
} catch (IOException e) {
e.printStackTrace();
}
for (String s : arrayList) {
s = s.toLowerCase();//将学号变成小写
try {
bw.write(s);
} catch (IOException e) {
e.printStackTrace();
}
try {
bw.newLine();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bw.write(role);
} catch (IOException e) {
e.printStackTrace();
}
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("添加成功");
}
}
public static void addAccount() {
//添加账户
System.out.println("请输入要添加账户的UID");
String uid = TSUtility.readKeyBoard(10, false);
User addAccountUser = null;
try {
addAccountUser = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (addAccountUser != null) {
if (addAccountUser.getUserAccount() != null) {
System.out.println("您要添加账户的用户已有账户");
System.out.println("账户详情为:");
System.out.println(addAccountUser.getUserAccount());
} else {
addAccountUser.setUserAccount(new UserAccount(uid, 5, 0));
System.out.println(addAccountUser.getUserAccount());
try {
IOUtility.writeUser(uid, addAccountUser);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("添加账户成功");
}
} else {
System.out.println("您要添加账户的用户不存在");
}
}
public static void delAccount() {
//删除账户(在user里将account给赋值null)
PrintUtility.printWithColor("红色", "删除用户账户(慎重)");
PrintUtility.printWithColor("红色", "请输入要删除的账户UID");
String uid = TSUtility.readKeyBoard(10, false);
User delAccountUser = null;
try {
delAccountUser = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (delAccountUser != null) {
if (delAccountUser.getUserAccount() != null) {
delAccountUser.setUserAccount(null);
try {
IOUtility.writeUser(uid, delAccountUser);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("删除账户成功");
} else {
System.out.println("您要删除的用户账户没有账户");
}
} else {
System.out.println("您要删除的账户不存在");
}
}
public static void delUser() {
//删除用户
PrintUtility.printWithColor("红色", "删除用户(慎重)");
PrintUtility.printWithColor("红色", "请输入要删除的用户的UID(慎重)");
String dUID = TSUtility.readKeyBoard(10, false);
String dUser = IOUtility.findUser(dUID);
if (dUser == null) {
System.out.println("您要删除的用户不存在");
} else {
File file = new File(dUser);
file.delete();
System.out.println("删除成功");
}
}
public static void changePassword() {
//管理员修改任意账户的密码
System.out.println("请输入想要修改密码的用户UID:");
String chUID = TSUtility.readKeyBoard(10, false);
User chUser = null;
try {
chUser = IOUtility.readUser(chUID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (chUser != null) {
System.out.println("请输入该用户的姓名");
String chUsername = TSUtility.readKeyBoard(15, false);
if (chUsername.equals(chUser.getUserName())) {
System.out.println("请输入新密码:");
String newPassword1 = TSUtility.readKeyBoard(15, false);
System.out.println("请再次输入新密码:");
String newPassword2 = TSUtility.readKeyBoard(15, false);
if (newPassword1.equals(newPassword2)) {
chUser.setPassword(newPassword1);
try {
IOUtility.writeUser(chUID, chUser);
} catch (IOException e) {
e.printStackTrace();
}
PrintUtility.printWithColor("绿色", "修改成功\n新密码为:");
System.out.println(newPassword1);
} else {
PrintUtility.printWithColor("红色", "你输入的两次密码不一样");
}
}
} else {
System.out.println("您想要修改密码的账户不存在");
}
}
public static void inquireUser() {
//查询用户
PrintUtility.printWithColor("黄色", "请输入想要查询的用户UID:");
String inqUID = TSUtility.readKeyBoard(10, false);
User inqUser = null;
try {
inqUser = IOUtility.readUser(inqUID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (inqUser != null) {
System.out.println("查询成功," + inqUID + "用户的信息如下:");
System.out.println(inqUser);
} else {
System.out.println("查询失败,该用户不存在,正在返回上级菜单");
try {
TSUtility.loadSpecialEffects();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void inquireUserAccount() {
//查询账户
PrintUtility.printWithColor("黄色", "请输入想要查询的账户的用户UID:");
String inqUID = TSUtility.readKeyBoard(10, false);
User inqUserAccount = null;
try {
inqUserAccount = IOUtility.readUser(inqUID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (inqUserAccount != null) {
if (inqUserAccount.getUserAccount() != null) {
PrintUtility.printWithColor("黄色", "查询成功," + inqUID + "的账户的信息如下:");
System.out.println(inqUserAccount.getUserAccount());
} else {
PrintUtility.printWithColor("黄色", "您查看的用户账户不存在,请新建该账户");
return;
}
} else {
System.out.println("查询失败,该用户不存在,正在返回上级菜单");
try {
TSUtility.loadSpecialEffects();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static void inquireJob() {
//查询已投放职位
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (list == null || list.isEmpty() || list.size() == 0) {
System.out.println("还没有投放职位,先去投放职位吧");
return;
}
System.out.println("下面是所有已投放的兼职:");
System.out.println("---------------------------------------------");
for (Job job : list) {
System.out.println(job);
System.out.println("---------------------------------------------");
}
}
private static void delJob() {
//删除兼职信息
ArrayList<Job> jobs = null;
try {
jobs = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (jobs == null || jobs.isEmpty()) {
System.out.println("没有兼职被发布");
return;
}
System.out.println("所有兼职为");
System.out.println("------------------------");
for (Job job:jobs){
System.out.println(job);
System.out.println("------------------------");
}
System.out.println("输入你想要删除的兼职的JID");
String JID = TSUtility.readKeyBoard(10, false);
System.out.println("输入你想要删除的兼职的JTID");
String JTID = TSUtility.readKeyBoard(10, false);
for (Job job : jobs) {
if (job.getJID().equals(JID) && job.getJobType().getJTID().equals(JTID)) {
System.out.println("已找到该兼职,正在删除");
int index = jobs.indexOf(job);
jobs.remove(index);
try {
IOUtility.writeJob(jobs);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("删除成功,即将返回上层菜单");
return;
}
}
System.out.println("你删除的兼职不存在,即将返回上层菜单");
return;
}
}
用户操作
package service;
import domain.ApplyJob;
import domain.Job;
import domain.User;
import view.IOUtility;
import view.PrintUtility;
import view.TSUtility;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import static view.TSUtility.*;
public class UserService {
public static void informationModification(String UID) {
//个人信息修改
PrintUtility.printWithColor("黑色", "--修改个人信息--");
User nowUser = null;//创建当前对象
try {
nowUser = IOUtility.readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("想要修改的就输入内容,不想修改的就按回车跳过即可");
System.out.println("当前年龄为" + nowUser.getAge() + "\n输入新年龄");
nowUser.setAge(readAge(nowUser.getAge()));
System.out.println("当前性别为" + nowUser.getSex() + "\n输入新性别");
nowUser.setSex(readSex(nowUser.getSex()));
System.out.println("当前手机号为" + nowUser.getPhone() + "\n输入新手机号");
nowUser.setPhone(readPhone(nowUser.getPhone()));
System.out.println("当前部门为" + nowUser.getDepartment() + "\n输入新部门");
nowUser.setDepartment(readDepartment(nowUser.getDepartment()));
//保存
try {
if (IOUtility.writeUser(UID, nowUser)) {
System.out.println("修改成功");
System.out.println("修改后的年龄为:" + nowUser.getAge() + "\n性别为:" + nowUser.getSex()
+ "\n手机号为:" + nowUser.getPhone() + "\n部门为:" + nowUser.getDepartment());
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void revisePassword(String UID) {
//修改密码
while (true) {
PrintUtility.printChangePW();
PrintUtility.printWithColor("红色", "请务必记住修改后的新密码!");
User passUser = null;
try {
passUser = IOUtility.readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
PrintUtility.printWithColor("红色", "请输入旧密码");
String oldPw = readKeyBoard(15, false);
if (oldPw.equals(passUser.getPassword())) {
System.out.println("请输入新密码:");
String newPw = readKeyBoard(15, false);
if (newPw.equals(oldPw)) {
System.out.println("新密码不能和旧密码一样");
continue;
}
System.out.println("请再次输入新密码:");
String newPw2 = readKeyBoard(15, false);
if (newPw.equals(newPw2)) {
passUser.setPassword(newPw);
try {
if (IOUtility.writeUser(UID, passUser)) {
PrintUtility.printWithColor("绿色", "修改成功");
return;
} else {
System.out.println("修改失败");
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("两次输入的新密码不一样,修改失败");
continue;
}
} else {
System.out.println("现在的密码输入有误,修改失败");
continue;
}
}
}
public static void checkCredit_rating(String UID){
//信用等级查询
User rating = null;
try {
rating = IOUtility.readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
int ratingNum = rating.getUserAccount().getCredit_rating();
System.out.print("当前信用等级为:");
System.out.println(ratingNum);
if (ratingNum < 5) {
int times = 3 - rating.getIncrease();
System.out.println("按时完成" + times + "次兼职后信用等级恢复至" + (ratingNum + 1) + "级");
}
}
public static void checkBalance(String UID) {
//账户余额查询
User balance = null;
try {
balance = IOUtility.readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("当前账号余额为:");
double balanceNum = balance.getUserAccount().getBalance();
System.out.println(balanceNum);
}
public static void checkAllJob() {
//查询所有职位信息
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("下面是所有职位信息:");
System.out.println("---------------------------------------------");
for (Job job : list) {
System.out.println(job);
System.out.println("---------------------------------------------");
}
}
public static void checkCanDoJob(String UID) {
//查询可申请职位信息
//先将所有的job得到
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
User nowUser = null;
try {
nowUser = IOUtility.readUser(UID);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (nowUser.getUserAccount() == null) {
System.out.println("您没有账户,请联系管理员为您添加账户");
return;
}
System.out.println("下面是可以申请的职位信息:");
System.out.println("---------------------------------------------");
for (Job job : list) {
//是否可申请与信用等级、岗位所需人员、兼职时间相关
if (nowUser.getUserAccount().getCredit_rating() >= Integer.parseInt(job.getJob_level())) {
//信用等级大于等于需要的等级
if (job.getJob_demand() > 0) {
//需求人数大于0可以申请
Date now = new Date();//获得当前时间
Date endtime = new Date();//获取结束时间
String job_time = job.getJob_time();//yyyy-MM-dd到yyyy-MM-dd格式的时间
String[] str = job_time.split("到");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int m2 = Integer.parseInt(str[1].split("-")[1]);
int d2 = Integer.parseInt(str[1].split("-")[2]);
try {
endtime = sdf.parse(str[1]);
} catch (ParseException e) {
e.printStackTrace();
}
if (endtime.getTime() > now.getTime()) {
//结束时间比现在时间晚可以申请
System.out.println(job);
System.out.println("----------");
}
}
}
}
}
public static void jobApplication(String uid) {
//职位申请
checkCanDoJob(uid);
//先显示可以申请的职位
//然后将Applyjob.txtduc读出来,放在applyJobList中
ArrayList<ApplyJob> applyJobList = null;
try {
applyJobList = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
//判断一下该用户是否已经有兼职正在进行
//判断是不是空的
if (applyJobList != null && !applyJobList.isEmpty()) {
for (ApplyJob applyJob : applyJobList) {
if (applyJob.getUid().equals(uid)) {
if (applyJob.getState().equals("正在进行")) {
System.out.println("您有正在进行的兼职,请先完成该工作再申请其他工作吧!");
System.out.println("返回上级菜单");
TSUtility.readReturn();
return;
}
}
}
}
//创建一个新的applyjob对象,用来存放这次的兼职申请
ApplyJob nApplyJob = new ApplyJob();
//获取当前用户信息
User nowUser = null;
try {
nowUser = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (nowUser.getUserAccount().getCredit_rating() == 0) {
System.out.println("您的信用等级太低,无法申请兼职,马上为您返回上级菜单");
return;
}
//获取joblist
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("请输入想要申请的职位兼职营业执照编号(JID)");
String JID = TSUtility.readKeyBoard(10, false);
System.out.println("请输入想要申请的职位兼职类型标号(JTID)");
String JTID = TSUtility.readKeyBoard(10, false);
//找到想要的申请的兼职
for (Job job : list) {
if (JID.equals(job.getJID()) && JTID.equals(job.getJobType().getJTID())) {
//确定该job是我们想要的那个
if (job.getJob_demand() > 0) {
//可以申请(人数余量)
if (nowUser.getUserAccount().getCredit_rating() >= Integer.parseInt(job.getJob_level())) {
//信用等级大于该job的等级
Date nowtime = new Date();//获得当前时间
Date endtime = new Date();//获取结束时间
String job_time = job.getJob_time();//yyyy-MM-dd到yyyy-MM-dd格式的时间
String[] str = job_time.split("到");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int m2 = Integer.parseInt(str[1].split("-")[1]);
int d2 = Integer.parseInt(str[1].split("-")[2]);
try {
endtime = sdf.parse(str[1]);
} catch (ParseException e) {
e.printStackTrace();
}
if (endtime.getTime() > nowtime.getTime()) {
//结束时间比现在时间晚可以申请
//打印该工作
System.out.println("想要申请的兼职信息如下:");
System.out.println(job);
int demand = job.getJob_demand() - 1;
job.setJob_demand(demand);//将该人数减一
//将当前用户uid存入applyjob对象中
nApplyJob.setUid(uid);
//将姓名放入该对象
nApplyJob.setName(nowUser.getUserName());
//将兼职jid存入该对象
nApplyJob.setJid(job.getJID());
//将当前时间作为开始时间存入该对象
nApplyJob.setWork_start(nowtime);
//将该兼职的结束时间作为结束时间存入该对象
nApplyJob.setWork_end(endtime);
//将该兼职的名称存入该对象
nApplyJob.setJobName(job.getJob_name());
//将该兼职的兼职类型标号存入该对象
nApplyJob.setJTID(job.getJobType().getJTID());
//完成兼职申请,将其存储到applyjoblist中
applyJobList.add(nApplyJob);
try {
IOUtility.writeApplyJob(applyJobList);
} catch (IOException e) {
e.printStackTrace();
}
// list.add(job);
try {
IOUtility.writeJob(list);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("申请成功,即将自动退回上级菜单");
return;
} else {
System.out.println("您选择的兼职已结束,不能申请该兼职!");
break;
}
} else {
System.out.println("您的信用等级不足,不能申请该兼职!");
break;
}
} else {
System.out.println("需要的人数不足,不能申请该兼职!");
break;
}
}
}
System.out.println("您想要申请的兼职不存在");
}
public static void jobFinishes(String uid) {
//结束工作
ArrayList<ApplyJob> applyJobs = null;
try {
applyJobs = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (applyJobs.isEmpty()) {
System.out.println("还没有兼职被申请");
return;
}
User user = null;
try {
user = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (user.getUserAccount() == null) {
System.out.println("您没有账户,请联系管理员为您添加账户");
return;
}
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (list == null || list.isEmpty()) {
System.out.println("还没有兼职被发布");
return;
}
for (ApplyJob applyJob : applyJobs) {
if (applyJob.getUid().equals(uid) && applyJob.getState().equals("正在进行")) {
//找到是当前用户申请的兼职
System.out.println("找到您申请的兼职,正在结束工作,请稍后");
Date startTime = applyJob.getWork_start();//开始时间
Date endTime = applyJob.getWork_end();//设定好的结束时间
System.out.println("请输入想要结束工作的时间(格式为yyyy-MM-dd)");
Date wantEndTime = TSUtility.readWantEndTime(startTime);//想要结束的时间,需要手动输入
//判定是否逾期
if (wantEndTime.getTime() > endTime.getTime()) {
//逾期了,给信用等级-1,increase变为0
user.setIncrease(0);
int credit_rating = user.getUserAccount().getCredit_rating() - 1;
user.getUserAccount().setCredit_rating(credit_rating);
if (user.getUserAccount().getCredit_rating() <= 0) {
System.out.println("您的信用等级过低,以后无法申请兼职");
user.getUserAccount().setCredit_rating(0);
}
System.out.println("您已逾期,信用等级下降一级,当前等级为" + user.getUserAccount().getCredit_rating());
//逾期了多少天
long lateDay = (wantEndTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24);
System.out.println("您已逾期" + lateDay + "天");
for (Job job : list) {
if (job.getJID().equals(applyJob.getJid()) && job.getJobType().getJTID().equals(applyJob.getJTID())) {
//算出每天需要扣除的钱
double lataMoney = job.getJobType().getSalary() * job.getJobType().getDeduct_salary();
//算出薪水被扣后剩下的钱
double deductMoney = job.getJobType().getSalary() - (lateDay * lataMoney);
if (deductMoney < 0) {
//薪水扣完发现不够了,开始扣余额
double balance = user.getUserAccount().getBalance() + deductMoney;
if (balance <= 0) {
//余额也不够扣了,就把余额扣光
balance = 0;
System.out.println("结束成功,逾期时间太长,不仅薪水已经扣光了,账户余额也被扣光了");
} else {
System.out.println("结束成功,逾期时间太长,薪水已经扣光了");
}
user.getUserAccount().setBalance(balance);
} else {
//薪水扣完还有结余
double balance = user.getUserAccount().getBalance() + deductMoney;
user.getUserAccount().setBalance(balance);
System.out.println("结束成功,已经将剩余薪水打入您的账户");
}
}
}
//结算完成,存进文件去
try {
IOUtility.writeUser(uid, user);
} catch (IOException e) {
e.printStackTrace();
}
applyJob.setState("逾期完成");
applyJobs.add(applyJob);
try {
IOUtility.writeApplyJob(applyJobs);
} catch (IOException e) {
e.printStackTrace();
}
return;
} else {
//没有逾期,正常完成
for (Job job : list) {
if (job.getJID().equals(applyJob.getJid())
&& job.getJobType().getJTID().equals(applyJob.getJTID())) {
//找到这个工作
//将薪水加上用户的余额,然后存在用户账户里
double balance = user.getUserAccount().getBalance() + job.getJobType().getSalary();
user.getUserAccount().setBalance(balance);
try {
IOUtility.writeUser(uid, user);
} catch (IOException e) {
e.printStackTrace();
}
applyJob.setState("按时完成");
System.out.println("结束成功,已经将薪水打入您的账户");
try {
IOUtility.writeApplyJob(applyJobs);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (user.getUserAccount().getCredit_rating() == 5) {
//信用等级正常就返回
break;
} else {
//没有逾期,但是账户信用等级不到五
int increase = user.getIncrease() + 1;
if (increase < 2) {
user.setIncrease(increase);
System.out.println("你还需要按时完成" + (3 - increase) + "次兼职才能提升信用等级到" + (user.getUserAccount().getCredit_rating() + 1) + "级");
try {
IOUtility.writeUser(uid, user);
} catch (IOException e) {
e.printStackTrace();
}
break;
} else if (increase == 3) {
user.setIncrease(0);
int credit_rating = user.getUserAccount().getCredit_rating() + 1;
user.getUserAccount().setCredit_rating(credit_rating);
try {
IOUtility.writeUser(uid, user);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("按时完成兼职,您的信用等级已提升至" + credit_rating + "级");
}
}
}
}
}
}
public static void checkFinishJob(String uid) {
//查询已完成兼职
//获得applyjob数组
ArrayList<ApplyJob> applyJobs = null;
try {
applyJobs = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (applyJobs.isEmpty()) {
System.out.println("还没有兼职被申请");
return;
}
//获取user对象
User user = null;
try {
user = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
//获取job数组
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
//查询自己已经完成的工作
//先找到applyjob中被自己绑定的工作,然后找到这个工作的信息,输出工作信息和完成状态
System.out.println("已经完成的工作有:");
System.out.println("--------------");
for (ApplyJob applyJob : applyJobs) {
if (applyJob.getUid().equals(uid)) {
if (applyJob.getState().equals("逾期完成") || applyJob.getState().equals("按时完成")) {
for (Job job : list) {
if (job.getJID().equals(applyJob.getJid()) && job.getJobType().getJTID().equals(applyJob.getJTID())) {
System.out.println(job + "完成状态:" + applyJob.getState());
System.out.println("--------------");
}
}
}
}
}
}
public static void checkDoingJob(String uid) {
//查询正在兼职的信息
//获得applyjob数组
ArrayList<ApplyJob> applyJobs = null;
try {
applyJobs = IOUtility.readApplyJobList();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (applyJobs.isEmpty()) {
System.out.println("还没有兼职被申请");
return;
}
//获取user对象
User user = null;
try {
user = IOUtility.readUser(uid);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
//获取job数组
ArrayList<Job> list = null;
try {
list = IOUtility.readJob();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
//查询自己的正在进行的工作
System.out.println("正在进行的兼职是:");
for (ApplyJob applyJob : applyJobs) {
if (applyJob.getState().equals("正在进行") && applyJob.getUid().equals(uid)) {
for (Job job : list) {
if (applyJob.getJid().equals(job.getJID()) && applyJob.getJTID().equals(job.getJobType().getJTID())) {
System.out.println(job + applyJob.getState());
return;
}
}
}
}
}
}
管理员界面
package view;
import service.InformationDelivery;
import service.InformationMaintenance;
import service.SystemAdministration;
public class adminView {
//管理员操作选择界面
public static void adminWork() {
while (true) {
PrintUtility.printadminMainMenu();
char choose = TSUtility.readForth();
if (choose == '1') {
//基本信息维护界面
InformationMenu();
} else if (choose == '2') {
//兼职信息投放
deliveryMenu();
} else if (choose == '3') {
//系统管理
SystemMenu();
} else if (choose == '4') {
//退出系统
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
//管理员基本信息维护界面具体方法在InformationMaintenance.java内
public static void InformationMenu() {
while (true) {
PrintUtility.printadminMaintenance();
char choose = TSUtility.readForth();
switch (choose) {
case '1':
//兼职等级设置
InformationMaintenance.jobLevelSet();
break;
case '2':
//兼职类型设置(包含逾期费用扣除比例的调整)
InformationMaintenance.jobTypeSet();
break;
case '3':
//用户信用调整
InformationMaintenance.userCredit_ratingSet();
break;
case '4':
//退出
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
//管理员兼职信息投放
public static void deliveryMenu() {
while (true) {
PrintUtility.printDeliveryMenu();
char choose = TSUtility.readTwo();
switch (choose) {
case '1':
//兼职信息录入
InformationDelivery.jobInput();
break;
case '2':
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
//管理员系统管理
public static void SystemMenu() {
while (true) {
PrintUtility.printSystemMenuMenu();
char choose = TSUtility.readForth();
switch (choose) {
case '1':
//删除账户、删除用户、兼职信息删除
SystemAdministration.delModule();
break;
case '2':
//添加用户、添加账户、修改账户密码
SystemAdministration.addModule();
break;
case '3':
//查询用户、查询账户、查询已投放职位
//查询已完成职位、查询逾期兼职信息
SystemAdministration.inquireModule();
break;
case '4':
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
}
用户界面
package view;
import service.UserService;
import java.io.IOException;
public class UserView {
//普通用户登录后界面
public static void userMainMenu(String UID) throws IOException, ClassNotFoundException {
while (true) {
PrintUtility.printUserMainMenu();
char choose = TSUtility.readThree();
if (choose == '1') {
//个人信息管理
userMessage(UID);
} else if (choose == '2') {
//兼职申请
jobApplication(UID);
} else {
//退出
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
//个人信息管理界面
public static void userMessage(String UID) throws IOException, ClassNotFoundException {
while (true) {
PrintUtility.printMessage();
char choose = TSUtility.readFive();
switch (choose) {
case '1':
//个人信息修改
UserService.informationModification(UID);
break;
case '2':
//个人密码修改
UserService.revisePassword(UID);
break;
case '3':
//信用等级查询
UserService.checkCredit_rating(UID);
break;
case '4':
//个人余额查询
UserService.checkBalance(UID);
break;
case '5':
//退出
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
//兼职申请界面 实现代码在UserService.java中
private static void jobApplication(String UID) {
while(true){
PrintUtility.printjobApplication();
char choose =TSUtility.readSeven();
switch (choose){
case '1':
//查询所有职位信息
UserService.checkAllJob();
break;
case '2':
//查询可申请职位信息
UserService.checkCanDoJob(UID);
break;
case '3':
//职位申请
UserService.jobApplication(UID);
break;
case '4':
//结束工作
UserService.jobFinishes(UID);
break;
case '5':
//查询已完成兼职
UserService.checkFinishJob(UID);
break;
case '6':
//查询正在兼职的信息
UserService.checkDoingJob(UID);
break;
case '7':
//退出
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
}
登录注册界面
package view;
import domain.User;
import java.io.IOException;
import java.util.ArrayList;
public class LoginView {//实现登录注册
public static void loginOptions() throws IOException, InterruptedException, ClassNotFoundException {
while (true) {
PrintUtility.printWelcome();
PrintUtility.printHomePage();
char choose = TSUtility.readForth();
if (choose == '1') {//登录
if (signIn()) {
break;
}
} else if (choose == '2') {//注册
if (register()) {
signIn();
}
} else if (choose == '3') {//找回密码
if (recoverPassword()) {
loginOptions();
}
} else {//退出系统
System.out.print("确认是否退出(Y/N):");
if (TSUtility.readConfirmSelection() == 'Y') {
return;
} else {
break;
}
}
}
}
public static boolean signIn() throws IOException, InterruptedException, ClassNotFoundException {
//登录
PrintUtility.printSignIn();
int count = 0;
while (true) {
PrintUtility.printWithColor("白色", "请输入用户UID:");
String userUID = TSUtility.readKeyBoard(10, false);
PrintUtility.printWithColor("白色", "请输入用户密码:");
String password = TSUtility.readKeyBoard(15, false);
User userCheck = IOUtility.readUser(userUID);
if (userCheck != null) {
if (password.equals(userCheck.getPassword())) {
if (userUID.startsWith("s")) {
//判断是管理员还是学生(兼职人员)
//转到学生登录后界面
System.out.println("登录成功,当前为学生账户!");
TSUtility.loadSpecialEffects();
UserView.userMainMenu(userUID);
//转到学生(兼职人员界面)
} else if (userUID.startsWith("t")) {
//判断是不是管理员
System.out.println("登录成功,当前为管理员账户!");
TSUtility.loadSpecialEffects();
//转到管理员界面
adminView.adminWork();
}
} else {
System.out.println("您输入的密码不对,请重新输入");
count++;
return false;
}
} else {
System.out.println("您想要登录的用户不存在");
return false;
}
}
}
public static boolean register() throws IOException, ClassNotFoundException, InterruptedException {
//注册
PrintUtility.printRegister();
while (true) {
String sname = "E:\\Campus_Part_time\\src\\view\\userList.txt";
PrintUtility.printWithColor("白色", "请输入用户UID:");
String rUID = TSUtility.readKeyBoard(10, false);
PrintUtility.printWithColor("白色", "请输入用户姓名:");
String rName = TSUtility.readKeyBoard(10, false);
//判断能否注册
String rUser = rUID + "=" + rName;
ArrayList<String> arrayList = new ArrayList<>();
arrayList = IOUtility.getRole(sname);//从文件中获取角色,存入数组之中
boolean fl = true;
for (String s : arrayList) {//遍历数组
s = s.toLowerCase();//将学号变成小写
if (s.equals(rUser)) {//判断是否存在,存在即可注册
fl = false;
break;
}
}
if (fl) {
System.out.println("你不是已录入系统的用户,无法注册,请联系管理员");
return false;
}
if (IOUtility.readUser(rUID) != null) {//
System.out.println("您注册的用户已经存在,请直接登录或检查输入是否正确");
return false;
}
PrintUtility.printWithColor("白色", "请输入用户密码:");
String rPassword = TSUtility.readKeyBoard(15, false);
PrintUtility.printWithColor("白色", "请再次输入密码:");
String rPassword2 = TSUtility.readKeyBoard(15, false);
if (rPassword.equals(rPassword2)) {
User user = new User(rUID, rPassword, rName);
if (IOUtility.writeUser(rUID, user)) {
System.out.println("注册成功");
TSUtility.loadSpecialEffects();
return true;
} else {
System.out.println("注册失败");
return false;
}
}
}
}
public static boolean recoverPassword() throws IOException, ClassNotFoundException {
//找回密码
while (true) {
PrintUtility.printFindPassword();
System.out.println("请输入注册时的UID");
String userUID = TSUtility.readKeyBoard(10, false);
System.out.println("请输入注册时的用户姓名");
String userName = TSUtility.readKeyBoard(10, false);
User findPassword = IOUtility.readUser(userUID);//反序列化用户对象
if (findPassword == null) {
System.out.println("你想找回密码的账户不存在,请注册");
return false;
}
if (userName.equals(findPassword.getUserName())) {
//如果UID对了,并且姓名也对了,就输出他设置的密码
System.out.println("您UID为" + userUID + "账户名为" + userName + "的账户密码是" + findPassword.getPassword());
return true;
} else {
System.out.println("输入的姓名有误,请输入注册时正确的姓名!");
return false;
}
}
}
}
io工具
package view;
import domain.ApplyJob;
import domain.User;
import java.io.*;
import java.util.ArrayList;
public class IOUtility {
private static File accountRoot = new File("E:\\Campus_Part_time\\src\\view\\UserFile");
private static File jobFile = new File("E:\\Campus_Part_time\\src\\service\\job\\job.txt");
private static File applyJobFile = new File("E:\\Campus_Part_time\\src\\service\\job\\ApplyJob.txt");
public static ArrayList<String> getRole(String sname) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(sname));
String line;
ArrayList<String> arrayList = new ArrayList<>();
while ((line = br.readLine()) != null) {
arrayList.add(line);
}
br.close();
return arrayList;
}
public static String findUser(String UID) {
File[] files = accountRoot.listFiles();
for (File file : files) {
String fname = file.getName();
if (fname.equals(UID + ".txt")) {
return file.getAbsolutePath();
}
}
return null;
}
//读取用户对象,没有则返回null
public static User readUser(String UID) throws IOException, ClassNotFoundException {
User user;
File[] files = accountRoot.listFiles();//遍历文件夹
for (File file : files) {
String fname = file.getName();//获取文件
if (fname.equals(UID + ".txt")) {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
Object obj = ois.readObject();
user = (User) obj;
ois.close();
return user;
}
}
return null;
}
//创建以UID.txt的用户对象序列化,成功就返回true
public static boolean writeUser(String UID, User user) throws IOException {
File file = new File(accountRoot, UID + ".txt");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(user);
oos.close();
return true;
}
public static <T> ArrayList<T> readJob() throws IOException, ClassNotFoundException {
//获取全部job,返回一个ArrayList集合
if (jobFile == null || jobFile.length() == 0 || !jobFile.exists()) {
return new ArrayList<T>();
} else {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(jobFile));
Object obj = ois.readObject();
ArrayList<T> jobList = (ArrayList<T>) obj;
ois.close();
return jobList;
}
}
//将job存储
public static <T> void writeJob(ArrayList<T> jobList) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(jobFile));
oos.writeObject(jobList);
oos.close();
}
public static ArrayList<ApplyJob> readApplyJobList() throws IOException, ClassNotFoundException {
if (applyJobFile == null || applyJobFile.length() == 0 || !applyJobFile.exists()) {
//先判断是不是空的或者该文件存在不存在
return new ArrayList<ApplyJob>();
} else {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(applyJobFile));
Object obj = ois.readObject();
ArrayList<ApplyJob> applyJobList = (ArrayList<ApplyJob>) obj;
ois.close();
return applyJobList;
}
}
public static void writeApplyJob(ArrayList<ApplyJob> applyJobList) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(applyJobFile));
oos.writeObject(applyJobList);
oos.close();
}
}
打印工具
package view;
import java.util.HashMap;
import java.util.Map;
public class PrintUtility {
public PrintUtility() {
}
//带颜色的打印content内容
public static void printWithColor(String color, String content) {
Map<String, String> map = new HashMap<>();
map.put("黑色", "30");
map.put("红色", "31");
map.put("绿色", "32");
map.put("黄色", "33");
map.put("蓝色", "34");
map.put("紫红色", "35");
map.put("青蓝色", "36");
map.put("白色", "37");
System.out.println("\033[1;" + map.get(color) + "m" + content + "\033[0m ");
}
//打印欢迎界面
public static void printWelcome() {
printWithColor("蓝色", "\t\tWelcome to My program");
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ 欢迎来到校园兼职软件 ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏";
printWithColor("黑色", s1);
}
public static void printHomePage() {
String s1 = "🐘-----------<请您先登录平台>---------------🐘\n" +
"🐘------------1.登录-----------------------🐘\n" +
"🐘------------2.注册-----------------------🐘\n" +
"🐘------------3.找回密码-------------------🐘\n" +
"🐘------------4.退出系统-------------------🐘\n" +
"请输入选择:";
printWithColor("黑色", s1);
}
public static void printdelModule() {
String s1 = "🐘-----------<请选择要删除的东西>---------------🐘\n" +
"🐘------------1.账户---------------------------🐘\n" +
"🐘------------2.用户---------------------------🐘\n" +
"🐘------------3.兼职信息-----------------------🐘\n" +
"🐘------------4.退出---------------------------🐘\n" +
"请输入选择:";
printWithColor("黑色", s1);
}
//打印登入界面
public static void printSignIn() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <登录界面> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
printWithColor("白色", s1);
}
//打印注册界面
public static void printRegister() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <注册界面> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
printWithColor("黑色", s1);
}
public static void printFindPassword() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <找回密码> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
printWithColor("黑色", s1);
}
public static void printChangePW() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <修改密码> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n";
printWithColor("红色", s1);
}
public static void printadminMainMenu() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <管理员主菜单> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻1. <基本信息维护> *\n" +
"🐘2. <兼职信息投放> *\n" +
"🦁3. <系统管理> *\n" +
"🐻4. <退出软件> *\n" +
"请选择";
printWithColor("绿色", s1);
}
public static void printSystemMenuMenu() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <管理员系统管理界面> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻1. <删除操作> *\n" +
"🐘2. <添加修改> *\n" +
"🦁3. <查询模块> *\n" +
"🐻4. <退出> *\n" +
"请选择";
printWithColor("黄色", s1);
}
public static void printadminMaintenance() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <管理员信息维护界面> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻1. <兼职等级设置> *\n" +
"🐘2. <兼职类型设置> *\n" +
"🦁3. <用户信用调整> *\n" +
"🐎4. <退出> *\n" +
"请选择";
printWithColor("红色", s1);
}
public static void printAddModuleMenu() {
String s1 = "----------管理员添加操作模块---------\n" +
"🐻1. <添加用户> *\n" +
"🐘2. <添加账户> *\n" +
"🦁3. <修改账户密码> *\n" +
"🐎4. <返回上级菜单> *\n" +
"请选择";
printWithColor("绿色", s1);
}
public static void printInquireModule() {
String s1 = "----------管理员查询操作模块---------\n" +
"🐻1. <查询用户> *\n" +
"🐘2. <查询账户> *\n" +
"🦁3. <查询已投放职位> *\n" +
"🐎4. <查询已完成职位> *\n" +
"🐻5. <查询逾期兼职信息> *\n" +
"🐘6. <返回上级菜单> *\n" +
"请选择";
printWithColor("黄色", s1);
}
public static void printUserMainMenu() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <普通用户主菜单> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻1. <个人信息管理> *\n" +
"🐘2. <兼职申请> *\n" +
"🦁3. <退出> *\n" +
"请选择";
printWithColor("青蓝色", s1);
}
public static void printMessage() {
String s1 = "🐻 ~个人信息管理~ 🐻\n" +
"🐻 1. <个人信息修改> 🐻\n" +
"🐻 2. <个人密码修改> 🐻\n" +
"🐻 3. <信用等级查询> 🐻\n" +
"🐻 4. <个人余额查询> 🐻\n" +
"🐻 5. <退出当前菜单> 🐻\n" +
"请选择:";
printWithColor("黑色", s1);
}
public static void printDeliveryMenu() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <管理员投放兼职系信息菜单> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻1. <兼职信息录入> *\n" +
"🐘2. <退出> *\n" +
"请选择";
printWithColor("红色", s1);
}
//兼职申请界面
public static void printjobApplication() {
String s1 = "☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏☏\n" +
"☏ ☏\n" +
"☏ <欢迎来到用户兼职申请界面> ☏\n" +
"☏ ☏\n" +
"♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏♏\n" +
"🐻 1. <查询所有职位信息> \n" +
"🐻 2. <查询可申请职位信息> \n" +
"🐻 3. <职位申请> \n" +
"🐻 4. <结束工作> \n" +
"🐻 5. <查询已完成兼职> \n" +
"🐻 6. <查询正在兼职的信息> \n" +
"🐻 7. <退出当前菜单> \n" +
"请选择:";
printWithColor("绿色", s1);
}
}
工具类
package view;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
/*工具类*/
public class TSUtility {
private static Scanner scanner = new Scanner(System.in);
//读1-4的选择
public static char readForth() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
//读1-2的选择
public static char readTwo() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2') {
System.out.println("选择错误,请重新输入:");
} else break;
}
return c;
}
//读1-3的选择
public static char readThree() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3') {
System.out.println("选择错误,请重新输入:");
} else break;
}
return c;
}
public static char readFive() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4' && c != '5') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
public static char readSix() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4' && c != '5' && c != '6') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
public static char readSeven() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false);
c = str.charAt(0);
if (c != '1' && c != '2' &&
c != '3' && c != '4' && c != '5' && c != '6' && c != '7') {
System.out.print("选择错误,请重新输入:");
} else break;
}
return c;
}
//停下来,你按回车才继续执行
public static void readReturn() {
System.out.print("按回车键继续...");
readKeyBoard(100, true);
}
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static int readstock() {
int n;
for (; ; ) {
String str = readKeyBoard(6, false);
try {
n = Integer.parseInt(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static Double readDouble() {
Double n;
for (; ; ) {
String str = readKeyBoard(6, false);
try {
n = Double.parseDouble(str);
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
public static char readConfirmSelection() {
char c;
for (; ; ) {
String str = readKeyBoard(1, false).toUpperCase();
c = str.charAt(0);
if (c == 'Y' || c == 'N') {
break;
} else {
System.out.print("选择错误,请重新输入:");
}
}
return c;
}
public static String readString(int limit, String defaultValue) {
String str = readKeyBoard(limit, true);
return str.equals("") ? defaultValue : str;
}
public static String readKeyBoard(int limit, boolean blankReturn) {
String line = "";
while (scanner.hasNextLine()) {
line = scanner.nextLine();
if (line.length() == 0) {
if (blankReturn) return line;
else continue;
}
if (line.length() < 1 || line.length() > limit) {
System.out.print("输入长度(不大于" + limit + ")错误,请重新输入:");
continue;
}
break;
}
return line;
}
public static void loadSpecialEffects() throws InterruptedException {
System.out.println("请稍等:");
for (int i1 = 1; i1 <= 100; i1++) {
System.out.print("加载中:" + i1 + "%");
Thread.sleep(new Random().nextInt(25) + 1);
if (i1 == 100) {
Thread.sleep(50);
}
System.out.print("\r");
}
}
public static int readAge(int defaultValue) {//默认年龄
int age;
for (; ; ) {
String str = readKeyBoard(2, true);
try {
int newAge = Integer.parseInt(str);
age = newAge;
if (age == 0) {
return 0;
} else if (age < 18 || age > 50) {
System.out.println("输入的年龄不符合,要求兼职人员年龄在18-50岁之间。请重新输入:");
} else {
return age;
}
} catch (RuntimeException runtimeException) {
return defaultValue;
}
}
}
public static String readSex(String defaultValue) {
//修改年龄
String sex = null;
for (; ; ) {
String str = readKeyBoard(1, true);
sex = str.equals("") ? defaultValue : str;//如果回车跳过,则将默认值赋给sex
if (sex.equals("男") || sex.equals("女") || sex.equals("未知")) {
break;
} else {
System.out.println("输入有误,请重新输入");
}
}
return sex;
}
public static String readJobtype_name(String defaultValue) {
//修改兼职类型类型名
String jobType_name = null;
for (; ; ) {
String str = readKeyBoard(4, true);
jobType_name = str.equals("") ? defaultValue : str;//如果回车跳过,则将默认值赋给sex
break;
}
return jobType_name;
}
public static double readDeduct_salary(double defaultValue) {
//修改逾期比例
String deduct_salary = null;
for (; ; ) {
String str = readKeyBoard(2, true);
deduct_salary = str.equals("") ? String.valueOf(defaultValue * 100) : str;
break;
}
return Double.parseDouble(deduct_salary);
}
public static double readSalary(double defaultValue) {
String salary = null;
for (; ; ) {
String str = readKeyBoard(6, true);
salary = str.equals("") ? String.valueOf(defaultValue) : str;
break;
}
return Double.parseDouble(salary);
}
public static String readPhone(String defaultValue) {
//修改电话号码
String phone = null;
for (; ; ) {
String str = readKeyBoard(11, true);
phone = str.equals("") ? defaultValue : str;
if (phone.equals("未知")) {
return phone;
}
if (phone.length() == 11) {
break;
} else {
System.out.println("请输入11位电话号码");
}
}
return phone;
}
public static String readDepartment(String defaultValue) {
String department = null;
for (; ; ) {
String str = readKeyBoard(10, true);
department = str.equals("") ? defaultValue : str;
if (department.equals("未知")) {
return department;
}
return department;
}
}
public static String readlevel() {
String level = null;
level = String.valueOf(readFive());
return level;
}
public static Date readWantEndTime(Date Time) {
//yyyy-MM-dd
String time = null;
do {
try {
System.out.println("请先输入年(格式yyyy)");
String yyyy = readKeyBoard(4, false);
System.out.println("请在输入月(格式MM)");
int MM = readInt();
System.out.println("最后输入日(格式dd)");
int dd = readInt();
time = yyyy + "-" + MM + "-" + dd;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date wantEndTime = sdf.parse(time);
if (Time.getTime() <= wantEndTime.getTime()) {
if ((MM > 12 || dd > 31)) {
System.out.println("输入错误,请重新输入");
} else {
return wantEndTime;
}
} else {
System.out.println("结束工作时间应该比今日时间晚");
System.out.println("请重新输入:");
}
} catch (Exception e) {
System.out.println("输入错误,请重新输入!");
}
} while (true);
}
public static String readJobTime() {
//yyyy-MM-dd到yyyy-MM-dd
String time = null;
do {
try {
time = readKeyBoard(23, false);
String[] str = time.split("到");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int m1 = Integer.parseInt(str[0].split("-")[1]);
int m2 = Integer.parseInt(str[1].split("-")[1]);
int d1 = Integer.parseInt(str[0].split("-")[2]);
int d2 = Integer.parseInt(str[1].split("-")[2]);
Date date1 = sdf.parse(str[0]);
Date date2 = sdf.parse(str[1]);
Date now = new Date();
if (date1.getTime() > date2.getTime()) {
System.out.println("输入的开始时间应该比结束时间早!");
System.out.println("请重新输入:");
} else if (now.getTime() > date1.getTime()) {
System.out.println("开始时间应该比今日时间晚");
System.out.println("请重新输入:");
} else if ((m1 > 12 || m2 > 12 || d1 > 31 || d2 > 31)) {
System.out.println("输入错误,请重新输入");
} else {
return time;
}
} catch (Exception e) {
System.out.println("输入错误,请重新输入!");
}
} while (true);
}
}