重写之前的测试
public class PlanInformation {
private int id;//日报流水号
private String planid;//产品生产批次号(例如:2312-110,有8 位字符组成,前四位表示年月,后三位表示序号)
private String planname;//产品名称(例如:“表体”)
private String process;//工序名称(例如:“10.00 .射蜡”数字表示工序号,字符表示工序名称)
private String nextprocess;//下一接收工序名称(例如:“11.00 .修蜡”含义同上)
private String operator;//当前工序操作者
private String recipient;//下一道工序的接受者
private int plannumber;//产品定要要求的产品数量
private int innumber;//从上一道工序的接收的合格产品总数
private int outnumber;//当前工序的产品转出总数
private int missnumber;//当前工序的产品丢失数量
private int badnumber;//当前工序的产品废品数量
private int inspectednumber;//当前工序的产品待检验数量
private int statement;//日报记录的状态,0表示初始计划,1表示日报提交,2表示日报确认
public PlanInformation(int id,String planid,String planname,
String process,String nextprocess,String operator,String recipient,
int plannumber,int innumber,int outnumber,int missnumber,
int badnumber,int inspectednumber,int statement) {
this.id =id;
this.planid=planid;
this.planname=planname;
this.process=process;
this.nextprocess=nextprocess;
this.operator=operator;
this.recipient=recipient;
this.plannumber=plannumber;
this.innumber=innumber;
this.outnumber=outnumber;
this.missnumber=missnumber;
this.badnumber=badnumber;
this.inspectednumber=inspectednumber;
this.statement=statement;
}
public String getPlanname() {
return planname;
}
public void setPlanname(String planname) {
this.planname = planname;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPlanid() {
return planid;
}
public void setPlanid(String planid) {
this.planid = planid;
}
public String getProcess() {
return process;
}
public void setProcess(String process) {
this.process = process;
}
public String getNextprocess() {
return nextprocess;
}
public void setNextprocess(String nextprocess) {
this.nextprocess = nextprocess;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public int getPlannumber() {
return plannumber;
}
public void setPlannumber(int plannumber) {
this.plannumber = plannumber;
}
public int getInnumber() {
return innumber;
}
public void setInnumber(int innumber) {
this.innumber = innumber;
}
public int getOutnumber() {
return outnumber;
}
public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}
public int getMissnumber() {
return missnumber;
}
public void setMissnumber(int missnumber) {
this.missnumber = missnumber;
}
public int getBadnumber() {
return badnumber;
}
public void setBadnumber(int badnumber) {
this.badnumber = badnumber;
}
public int getInspectednumber() {
return inspectednumber;
}
public void setInspectednumber(int inspectednumber) {
this.inspectednumber = inspectednumber;
}
public int getStatement() {
return statement;
}
public void setStatement(int statement) {
this.statement = statement;
}
}
import java.util.Scanner;
public class PlanManagement {
private PlanInformation[] plans = new PlanInformation[5]; // 存储五个日报记录
private int planCount = 0; // 当前存储的日报记录数量
private Scanner scanner = new Scanner(System.in);
// 工艺流程表
private String[][] processTable = {
{"10", "射蜡", "柳泽羽"},
{"20", "修蜡", "藤艺哲"},
{"30", "面层", "郝一诺"},
{"40", "封浆", "杨松铎"},
{"50", "熔化", "刘宇恒"},
{"60", "切割", "陶攀印"},
{"70", "精磨", "阎琪文"},
{"80", "调型", "郝正一"},
{"90", "检验", "刘静一"}
};
//生成mes系统的最上面的三行
public void printThird(){
System.out.println("***********************************************************");
System.out.println(" 石家庄铁道大学无限23软件开发有限公司");
System.out.println(" Mes系统2023版");
System.out.println("***********************************************************");
}
// 主界面
public void printMainMenu() {
printThird();
System.out.println(" 1、生成计划");
System.out.println(" 2、提交日报");
System.out.println(" 3、确认日报");
System.out.println(" 4、统计进度");
System.out.println("***********************************************************");
}
//显示计划子界面
public void generateFrame(String planid,String planname,int plannumber){
printThird();
System.out.println("产品批次:" + planid);
System.out.println("产品名称:" + planname);
System.out.println("计划数量:" + plannumber);
System.out.println("***********************************************************");
}
// 生成计划
public void generatePlan() {
if (planCount >= 5) {
System.out.println("计划已满,无法生成新的计划。");
return;
}
System.out.println("请输入产品批次:");
String planid = scanner.nextLine();
System.out.println("请输入产品名称:");
String planname = scanner.nextLine();
System.out.println("请输入计划数量:");
int plannumber = scanner.nextInt();
scanner.nextLine();
generateFrame(planid,planname,plannumber);
System.out.println("该产品入库操作已完成,是否提交(Y/N)");
char choice = scanner.next().charAt(0);
scanner.nextLine();
if (choice == 'Y' || choice == 'y') {
plans[planCount] = new PlanInformation(planCount + 1, planid, planname, "", "", "", "", plannumber, 0, 0, 0, 0, 0, 0);
planCount++;
System.out.println("计划已提交。");
} else {
System.out.println("计划未提交。");
}
}
//打印产品批次、名称,计划数量
public void printData(PlanInformation[] plans,int i){
System.out.println("1、产品批次:" + plans[i].getPlanid());
System.out.println("2、产品名称:" + plans[i].getPlanname());
System.out.println("3、计划数量:" + plans[i].getPlannumber());
}
// 提交日报
public void submitDailyReport() {
printThird();
System.out.println("请输入产品批次号:");
String planid = scanner.nextLine();
for (int i = 0; i < planCount; i++) {
if (plans[i].getPlanid().equals(planid)) {
if (plans[i].getStatement() == 0) {
printThird();
printData(plans,i);
System.out.println("4、当前工序:");
String process = scanner.nextLine();
String operator = getoperator(process);
System.out.println("5、下一工序:");
String nextprocess = scanner.nextLine();
String recipient = getoperator(nextprocess);
System.out.println("6、操作员:" + operator);
System.out.println("7、接收员:" + recipient);
int innumber,outnumber,missnumber,badnumber,inspectednumber;
for(int j=0;;j++){
System.out.println("8、上一道工序转入数量:");
innumber = scanner.nextInt();
System.out.println("9、转出总数:");
outnumber = scanner.nextInt();
System.out.println("10、丢失数量:");
missnumber = scanner.nextInt();
System.out.println("11、废品数量:");
badnumber = scanner.nextInt();
System.out.println("12、待检验数量:");
inspectednumber = scanner.nextInt();
scanner.nextLine(); // 清除缓冲区
if (innumber != outnumber + missnumber + badnumber + inspectednumber) {
System.out.println("录入错误,请重新录入。");
continue;
}
else if(innumber == outnumber + missnumber + badnumber + inspectednumber) break;
}
System.out.println("***********************************************************");
System.out.println("选择(Y/y)将修改信息保存提交。选择(N/n),不保存修改信息返回系统主界面。");
char choice = scanner.next().charAt(0);
scanner.nextLine();
if (choice == 'Y' || choice == 'y') {
plans[i].setProcess(process);
plans[i].setNextprocess(nextprocess);
plans[i].setOperator(operator);
plans[i].setRecipient(recipient);
plans[i].setInnumber(innumber);
plans[i].setOutnumber(outnumber);
plans[i].setMissnumber(missnumber);
plans[i].setBadnumber(badnumber);
plans[i].setInspectednumber(inspectednumber);
plans[i].setStatement(1);
System.out.println("日报已提交。");
}
else {
System.out.println("日报未提交。");
}
}
else if (plans[i].getStatement() == 2) {
printThird();
printData(plans, i);
System.out.println("4、当前工序:"+plans[i].getProcess());
System.out.println("5、下一工序:"+plans[i].getNextprocess());
System.out.println("6、操作员:" + plans[i].getOperator());
System.out.println("7、接收员:" + plans[i].getRecipient());
System.out.println("8、上一道工序转入数量:"+plans[i].getInnumber());
int outnumber,missnumber,badnumber,inspectednumber;
for(int j=0;;j++){
System.out.println("9、转出总数:");
outnumber = scanner.nextInt();
System.out.println("10、丢失数量:");
missnumber = scanner.nextInt();
System.out.println("11、废品数量:");
badnumber = scanner.nextInt();
System.out.println("12、待检验数量:");
inspectednumber = scanner.nextInt();
scanner.nextLine(); // 清除缓冲区
if (plans[i].getInnumber() != outnumber + missnumber + badnumber + inspectednumber) {
System.out.println("录入错误,请重新录入。");
continue;
}
else if(plans[i].getInnumber() == outnumber + missnumber + badnumber + inspectednumber) break;
}
System.out.println("***********************************************************");
System.out.println("选择(Y/y)将修改信息保存提交。选择(N/n),不保存修改信息返回系统主界面。");
char choice = scanner.next().charAt(0);
scanner.nextLine(); // 清除缓冲区
if (choice == 'Y' || choice == 'y') {
plans[i].setOutnumber(outnumber);
plans[i].setMissnumber(missnumber);
plans[i].setBadnumber(badnumber);
plans[i].setInspectednumber(inspectednumber);
plans[i].setStatement(1);
System.out.println("日报已提交。");
}
else {
System.out.println("日报未提交。");
}
}
return;
}
}
System.out.println("库中没有该产品批次信息。");
}
// 确认日报
public void confirmDailyReport() {
printThird();
System.out.println("请输入产品批次号:");
String planid = scanner.nextLine();
for (int i = 0; i < planCount; i++) {
if (plans[i].getPlanid().equals(planid) && plans[i].getStatement() == 1) {
printThird();
printData(plans, i);
System.out.println("4、当前工序:" + plans[i].getProcess());
System.out.println("5、下一工序:" + plans[i].getNextprocess());
System.out.println("6、操作员:" + plans[i].getOperator());
System.out.println("7、接收员:" + plans[i].getRecipient());
System.out.println("8、上一道工序转入数量:" + plans[i].getInnumber());
System.out.println("9、转出总数:" + plans[i].getOutnumber());
System.out.println("10、丢失数量:" + plans[i].getMissnumber());
System.out.println("11、废品数量:" + plans[i].getBadnumber());
System.out.println("12、待检验数量:" + plans[i].getInspectednumber());
System.out.println("***********************************************************");
System.out.println("选择(Y/y)确认结果,并生成一条新的生产任务记录。选择(N/n),返回当前界面。");
char choice = scanner.next().charAt(0);
scanner.nextLine(); // 清除缓冲区
if (choice == 'Y' || choice == 'y') {
plans[i].setStatement(2);
System.out.println("日报已确认。");
return;
}
else {
System.out.println("日报未确认。");
confirmDailyReport();
}
return;
}
}
System.out.println("库中没有该产品批次信息或该批次状态不为1。");
}
//判断是否为最后一道工序
public boolean judgingProcess(PlanInformation[] plans,int i){
if(plans[i].getProcess().equals("检验")) return true;
else return false;
}
//统计成品数量
public int totalNumber(PlanInformation[] plans){
int sum=0;
for(int i=0;i<planCount;i++){
if(judgingProcess(plans,i)) sum+=plans[i].getOutnumber();
}
return sum;
}
// 统计进度
public void statistics() {
if (planCount == 0) {
System.out.println("没有计划记录。");
return;
}
printThird();
for (int i = 0; i < planCount; i++) {
printData(plans,i);
System.out.println("4、完成数量:" + plans[i].getOutnumber());
System.out.println("5、剩余数量:" + (plans[i].getPlannumber() - plans[i].getOutnumber()));
System.out.println("***********************************************************");
}
System.out.println("最后一道工序的成品总数:"+totalNumber(plans));
}
// 根据工序号获取操作员
private String getoperator(String process) {
for (String[] processInfo : processTable) {
if (processInfo[0].equals(process)) {
return processInfo[2];
}
}
return "";
}
// 运行系统
public void run() {
while (true) {
printMainMenu();
System.out.println("请选择:");
int choice = scanner.nextInt();
scanner.nextLine(); // 清除缓冲区
switch (choice) {
case 1:
generatePlan();
break;
case 2:
submitDailyReport();
break;
case 3:
confirmDailyReport();
break;
case 4:
statistics();
break;
default:
System.out.println("无效的选择,请重新输入。");
}
}
}
public static void main(String[] args) {
PlanManagement planManagement = new PlanManagement();
planManagement.run();
}
}