package com.kaoshi2;
import java.util.Scanner;
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;
}
// Getters and Setters
public int getId() {
return id;
}
public String getPlanid() {
return planid;
}
public String getPlanname() {
return planname;
}
public String getProcess() {
return process;
}
public String getNextprocess() {
return nextprocess;
}
public String getOperator() {
return operator;
}
public String getRecipient() {
return recipient;
}
public int getPlannumber() {
return plannumber;
}
public int getInnumber() {
return innumber;
}
public int getOutnumber() {
return outnumber;
}
public int getMissnumber() {
return missnumber;
}
public int getBadnumber() {
return badnumber;
}
public int getInspectednumber() {
return inspectednumber;
}
public int getStatement() {
return statement;
}
public void setStatement(int statement) {
this.statement = statement;
}
public void setInnumber(int innumber) {
this.innumber = innumber;
}
public void setOutnumber(int outnumber) {
this.outnumber = outnumber;
}
public void setMissnumber(int missnumber) {
this.missnumber = missnumber;
}
public void setBadnumber(int badnumber) {
this.badnumber = badnumber;
}
public void setInspectednumber(int inspectednumber) {
this.inspectednumber = inspectednumber;
}
}
class PlanUtils {
public static boolean dataFlatten(PlanInformation plan) {
// 数据压平逻辑
return plan.getOutnumber() == (plan.getMissnumber() + plan.getBadnumber() + plan.getInspectednumber());
}
public static boolean judgingProcess(PlanInformation plan) {
// 判断工序逻辑
return plan.getProcess().equals("90.检验");
}
public static int countPlan(PlanInformation[] plans) {
// 统计最后一道工序成品的总数量
int total = 0;
for (PlanInformation plan : plans) {
if (plan != null && judgingProcess(plan)) {
total += plan.getOutnumber();
}
}
return total;
}
}
class PlanManagement { // 系统类
private PlanInformation[] plans = new PlanInformation[5]; // 存储最多5个日报记录
private int num = 0; // 当前存储的日报数量
public static void main(String[] args) {
PlanManagement management = new PlanManagement();
management.mainFrame();
}
public void mainFrame() {
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("**********************************************************");
System.out.print("请选择功能(1-4):");
int choice = scanner.nextInt();
switch (choice) {
case 1:
generatePlan();
break;
case 2:
submitReport();
break;
case 3:
confirmReport();
break;
case 4:
countSchedule();
break;
default:
System.out.println("该选项不存在,请重新选择。");
}
}
}
public void generatePlan() {
Scanner scanner = new Scanner(System.in);
if (num >= plans.length) {
System.out.println("存储已满,无法生成新计划。");
return;
}
String planid;
while (true) {
System.out.print("请输入产品批次(格式:YYYY-XXX):");
planid = scanner.next();
if (checkValidity(planid, "\\d{4}-\\d{3}")) {
break;
} else {
System.out.println("录入错误,格式应为YYYY-XXX");
}
}
System.out.print("请输入产品名称:");
String planname = scanner.next();
System.out.print("请输入计划数量:");
int plannumber = scanner.nextInt();
// 生成当前工序和下一工序
String process = "10.00.射蜡";
String nextprocess = "20.00.修蜡";
String operator = "柳泽羽";
String recipient = "藤艺哲";
PlanInformation pi = new PlanInformation(num + 1, planid, planname, process, nextprocess, operator, recipient, plannumber, 0, 0, 0, 0, 0, 0);
plans[num] = pi;
num++;
System.out.println("***********************************************************");
System.out.println(" 产品批次:" + pi.getPlanid());
System.out.println(" 产品名称:" + pi.getPlanname());
System.out.println(" 计划数量:" + pi.getPlannumber());
System.out.println("***********************************************************");
System.out.print("该产品入库操作已完成,是否提交(Y/N):");
char ch = scanner.next().charAt(0);
if (ch == 'Y' || ch == 'y') {
pi.setStatement(0); // 设置为初始计划状态
System.out.println("计划已提交。");
} else {
System.out.println("计划未提交,返回主界面。");
}
}
public void submitReport() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品批次号:");
String planid = scanner.next();
PlanInformation plan = findPlan(planid);
if (plan == null) {
System.out.println("库中没有该产品计划,返回提交界面。");
return;
}
if (plan.getStatement() != 0) {
System.out.println("该产品已提交日报,无法再次提交。");
return;
}
// 显示计划信息并获取用户输入
System.out.println("1、产品批次:" + plan.getPlanid());
System.out.println("2、产品名称:" + plan.getPlanname());
System.out.println("3、计划数量:" + plan.getPlannumber());
System.out.println("4、当前工序:" + plan.getProcess());
System.out.println("5、下一工序:" + plan.getNextprocess());
System.out.println("6、操作员:" + plan.getOperator());
System.out.println("7、接收员:" + plan.getRecipient());
System.out.print("8、上一道工序转入数量:");
int innumber = scanner.nextInt();
if (innumber > plan.getPlannumber()) {
System.out.println("转入数量不能大于计划数量,请重新输入。");
return;
}
System.out.print("9、转出总数:");
int outnumber = scanner.nextInt();
System.out.print("10、丢失数量:");
int missnumber = scanner.nextInt();
System.out.print("11、废品数量:");
int badnumber = scanner.nextInt();
System.out.print("12、待检验数量:");
int inspectednumber = scanner.nextInt();
// 验证数据一致性
if (!PlanUtils.dataFlatten(new PlanInformation(0, "", "", "", "", "", "", 0, innumber, outnumber, missnumber, badnumber, inspectednumber, 0))) {
System.out.println("转出总数应等于丢失数量 + 废品数量 + 待检验数量,请重新输入。");
return;
}
// 保存日报信息
plan.setInnumber(innumber);
plan.setOutnumber(outnumber);
plan.setMissnumber(missnumber);
plan.setBadnumber(badnumber);
plan.setInspectednumber(inspectednumber);
plan.setStatement(1); // 设置为已提交状态
System.out.println("日报已提交。");
}
public void confirmReport() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入产品批次号:");
String planid = scanner.next();
PlanInformation plan = findPlan(planid);
if (plan == null) {
System.out.println("库中没有该产品计划,返回确认日报界面。");
return;
}
if (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.getInnumber());
System.out.println("转出数量:" + plan.getOutnumber());
System.out.println("丢失数量:" + plan.getMissnumber());
System.out.println("废品数量:" + plan.getBadnumber());
System.out.println("待检验数量:" + plan.getInspectednumber());
System.out.print("是否确认日报(Y/N):");
char ch = scanner.next().charAt(0);
if (ch == 'Y' || ch == 'y') {
// 生成新的生产任务记录
plan.setStatement(2); // 设置为确认状态
System.out.println("日报已确认,状态已更新。");
} else {
System.out.println("日报未确认,返回主界面。");
}
}
public void countSchedule() {
int totalFinished = PlanUtils.countPlan(plans);
System.out.println("最后一道工序成品的总数量:" + totalFinished);
}
private PlanInformation findPlan(String planid) {
for (PlanInformation plan : plans) {
if (plan != null && plan.getPlanid().equals(planid)) {
return plan;
}
}
return null;
}
private boolean checkValidity(String str, String regex) {
return str.matches(regex);
}
}
标签:String,int,System,plan,println,考试,out From: https://www.cnblogs.com/Ma-yr/p/18440591