2024.9.29
信2305-3 20234094 刘奕阳
import java.util.Scanner;
public class MESSystem {
// 产品工艺表
private static final String[][] PROCESS_TABLE = {
{"10", "射蜡", "柳泽羽"},
{"20", "修蜡", "藤艺哲"},
{"30", "面层", "郝一诺"},
{"40", "封浆", "杨松铎"},
{"50", "熔化", "刘宇恒"},
{"60", "切割", "陶攀印"},
{"70", "精磨", "阎琪文"},
{"80", "调型", "郝正一"},
{"90", "检验", "刘静一"}
};
private static PlanInformation[] records = new PlanInformation[5];
private static int recordCount = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("***********************************************************");
System.out.println("石家庄铁道大学无限23软件开发有限公司");
System.out.println("Mes系统2023版");
System.out.println("***********************************************************");
System.out.println("1、生成计划");
System.out.println("2、提交日报");
System.out.println("3、确认日报");
System.out.println("4、统计进度");
System.out.println("**********************************************************");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
generatePlan(scanner);
break;
case 2:
submitDailyReport(scanner);
break;
case 3:
confirmDailyReport(scanner);
break;
case 4:
reportProgress();
break;
default:
System.out.println("该选项不存在");
break;
}
}
}
private static void generatePlan(Scanner scanner) {
System.out.println("请输入产品批次:");
String planid = scanner.nextLine();
System.out.println("请输入产品名称:");
String planname = scanner.nextLine();
System.out.println("请输入计划数量:");
int plannumber = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.println("***********************************************************");
System.out.println("产品批次:" + planid);
System.out.println("产品名称:" + planname);
System.out.println("计划数量:" + plannumber);
System.out.println("该产品入库操作已完成,是否提交(Y/N)");
String choice = scanner.nextLine();
if ("Y".equalsIgnoreCase(choice)) {
PlanInformation plan = new PlanInformation(recordCount + 1, planid, planname,
PROCESS_TABLE[0][1], PROCESS_TABLE[1][1],
PROCESS_TABLE[0][2], PROCESS_TABLE[1][2],
plannumber, 0, 0, 0, 0, 0, 0);
records[recordCount++] = plan;
}
}
private static void submitDailyReport(Scanner scanner) {
System.out.println("请输入产品批次号:");
String planid = scanner.nextLine();
PlanInformation plan = findPlanById(planid);
if (plan == null) {
System.out.println("库中没有该产品计划");
return;
}
if (plan.getStatement() == 0) {
recordDailyReport(scanner, plan);
}
}
private static void recordDailyReport(Scanner scanner, PlanInformation plan) {
System.out.println("产品批次:" + plan.getPlanid());
System.out.println("产品名称:" + plan.getPlanname());
System.out.println("计划数量:" + plan.getPlannumber());
System.out.println("当前工序:" + plan.getProcess());
System.out.println("下一工序:" + plan.getNextprocess());
System.out.println("操作员:" + plan.getOperator());
System.out.println("接收员:" + plan.getRecipient());
int currentIndex = getProcessIndex(plan.getProcess());
if (currentIndex > 0) {
System.out.println("上一道工序转入数量:");
int innumber = scanner.nextInt();
plan.setInnumber(innumber);
}
System.out.println("转出总数:");
int outnumber = scanner.nextInt();
System.out.println("丢失数量:");
int missnumber = scanner.nextInt();
System.out.println("废品数量:");
int badnumber = scanner.nextInt();
System.out.println("待检验数量:");
int inspectednumber = scanner.nextInt();
scanner.nextLine(); // Consume newline
if (plan.getInnumber() != outnumber + missnumber + badnumber + inspectednumber) {
System.out.println("录入错误信息,请更改上述三个数量");
return;
}
plan.setOutnumber(outnumber);
plan.setMissnumber(missnumber);
plan.setBadnumber(badnumber);
plan.setInspectednumber(inspectednumber);
System.out.println("确认提交(Y/N)");
String choice = scanner.nextLine();
if ("Y".equalsIgnoreCase(choice)) {
plan.setStatement(1);
}
}
private static void confirmDailyReport(Scanner scanner) {
System.out.println("请输入产品批次:");
String planid = scanner.nextLine();
PlanInformation plan = findPlanById(planid);
if (plan == null || plan.getStatement() != 1) {
System.out.println("库中没有该产品批次或状态不正确");
return;
}
System.out.println("产品批次:" + plan.getPlanid());
System.out.println("产品名称:" + plan.getPlanname());
System.out.println("计划数量:" + plan.getPlannumber());
System.out.println("当前工序:" + plan.getProcess());
System.out.println("下一工序:" + plan.getNextprocess());
System.out.println("操作员:" + plan.getOperator());
System.out.println("接收员:" + plan.getRecipient());
System.out.println("上一道工序转入数量:" + plan.getInnumber());
System.out.println("确认结果并生成新任务记录(Y/N)");
String choice = scanner.nextLine();
if ("Y".equalsIgnoreCase(choice)) {
int currentIndex = getProcessIndex(plan.getProcess());
plan.setStatement(2);
if (currentIndex + 1 < PROCESS_TABLE.length) {
PlanInformation newPlan = new PlanInformation(recordCount + 1, plan.getPlanid(), plan.getPlanname(),
PROCESS_TABLE[currentIndex + 1][1],
currentIndex + 2 < PROCESS_TABLE.length ? PROCESS_TABLE[currentIndex + 2][1] : "",
PROCESS_TABLE[currentIndex + 1][2],
currentIndex + 2 < PROCESS_TABLE.length ? PROCESS_TABLE[currentIndex + 2][2] : "",
plan.getPlannumber(), plan.getOutnumber() - plan.getMissnumber() - plan.getBadnumber() - plan.getInspectednumber(),
0, 0, 0, 0, 0);
records[recordCount++] = newPlan;
System.out.println("新的生产任务记录已生成");
}
}
}
private static void reportProgress() {
for (PlanInformation plan : records) {
if (plan != null) {
System.out.println("***********************************************************");
System.out.println("产品批次:" + plan.getPlanid());
System.out.println("产品名称:" + plan.getPlanname());
System.out.println("计划数量:" + plan.getPlannumber());
System.out.println("完成数量:" + ((plan.getStatement() == 2) ? plan.getOutnumber() : 0));
System.out.println("剩余数量:" + (plan.getPlannumber() - ((plan.getStatement() == 2) ? plan.getOutnumber() : 0)));
}
}
}
private static int getProcessIndex(String process) {
for (int i = 0; i < PROCESS_TABLE.length; i++) {
if (PROCESS_TABLE[i][1].equals(process)) {
return i;
}
}
return -1;
}
private static PlanInformation findPlanById(String planid) {
for (PlanInformation record : records) {
if (record != null && record.getPlanid().equals(planid)) {
return record;
}
}
return null;
}
}
class PlanInformation {
// 私有变量声明
private int id;
private String planid;
private String planname;
private String process;
private String nextprocess;
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;
// 构造函数
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;
}
// Getter 和 Setter 方法
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 getPlanname() {
return planname;
}
public void setPlanname(String planname) {
this.planname = planname;
}
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;
}
}