java學習9.13

臧博涛發表於2024-09-13

將java測試卷重新完成,測試完後基本完成需求,無明顯BUG

結合課堂上去寫這個java測試卷,總的來說,之前沒有獨立寫過類似專案+限時是比較大的問題。

如果之前沒有經歷類似的情況,很多功能都是第一次用,那麼就會導致出現bug而不知道如何去改,並且加上時間限制,如果時間全花在改bug上,又無法完成專案的需求。
除此之外,如果沒有專案經驗,那麼還會導致專案一開始的結構就很混亂,無法做到逐漸實現一塊塊功能,而是直接從上到下直接壘。

public class Main {
    public static void main(String[] args) {
        Planmanager pm = new Planmanager();
        pm.page();




    }
}

class PlaneInformation {

    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 inspectednubmer;//當前工序的產品待檢驗數量
    private int statement;//表示該日報記錄的狀態,0表示初始計劃,1表示日報提交,2表示日報確認。

    public PlaneInformation() {

    }

    public void PlaneInformation(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 inspectednubmer, 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.inspectednubmer = inspectednubmer;
        this.statement = statement;
    }

  public void  PlaneInformation() {

    }

    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 getInspectednubmer() {
        return inspectednubmer;
    }

    public void setInspectednubmer(int inspectednubmer) {
        this.inspectednubmer = inspectednubmer;
    }

    public int getStatement() {
        return statement;
    }

    public void setStatement(int statement) {
        this.statement = statement;
    }
}

import java.util.Scanner;
class Person
{
    int id;

    String Theworkname;
    String operator;

    public Person(int id,  String theworkname, String operator) {
        this.id = id;

        Theworkname = theworkname;
        this.operator = operator;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }



    public String getTheworkname() {
        return Theworkname;
    }

    public void setTheworkname(String theworkname) {
        Theworkname = theworkname;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }
}

public class Planmanager {

    PlaneInformation planeInformation[] = new PlaneInformation[1000];
    Person person[] = new Person[15];
    int idd = 0;

    public void page() {

        person[1] = new Person(1, "10.射蠟", "羽");
        person[2] = new Person(2, "20.修蠟", "哲");
        person[3] = new Person(3, "30.面層", "諾");
        person[4] = new Person(4, "40.封漿", "鐸");
        person[5] = new Person(5, "50.熔化", "恆");
        person[6] = new Person(6, "60.切割", "印");
        person[7] = new Person(7, "70.精磨", "文");
        person[8] = new Person(8, "80.調型", "正");
        person[9] = new Person(9, "90.檢驗", "靜");
        person[10] = new Person(10, "0.無", "無");
        person[11] = new Person(11, "-1.無", "無");


        boolean k = true;
        Scanner scc = new Scanner(System.in);
        while (k) {

            //主頁面
            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("5.退出系統");
            int Thechoice = scc.nextInt();
            switch (Thechoice) {
                //1、生成計劃"
                case 1: {
                    Creatework();

                    break;

                }

                //2、提交日報
                case 2: {
                    {
                        Submitreport();


                    }
                    break;

                }
                //3、確認日報
                case 3: {

                    Confirmreport();


                    break;
                }
                //4、統計進度
                case 4: {

                    Statisticprogress();


                    break;


                }
                //退出系統
                case 5: {
                    k = false;
                    break;
                }


                default: {

                    System.out.println("該選項不存在");
                }
            }
        }
    }

    public void Creatework() {
        boolean kk = true;
        while (kk) {
            Scanner sc = new Scanner(System.in);
            System.out.println("產品批次:");
            String planid = sc.next();
            while (planid.length() < 8 || planid.charAt(4) != '-') {
                System.out.println("輸入有問題,請重新輸入產品批次號");
                planid = sc.next();

            }
            System.out.println("產品名稱:");
            String planename1 = sc.next();
            System.out.println("計劃數量:");
            int plannumber1 = sc.nextInt();

            System.out.println("產品批次" + planid);
            System.out.println("產品名稱“" + planename1);
            System.out.println("計劃數量" + plannumber1);
            System.out.println("該產品入庫操作已完成,是否提交(Y/N)");
            String yesno = sc.next();
            planeInformation[0] = new PlaneInformation();
            if (yesno.equals("Y")) {
                planeInformation[0].setPlanid(planid);
                planeInformation[0].setPlanname(planename1);
                planeInformation[0].setPlannumber(plannumber1);
                planeInformation[0].setStatement(0);
                planeInformation[0].setInnumber(plannumber1);
                System.out.println("提交成功!");
                kk = false;

            }


        }
    }


    public void Submitreport() {
        Scanner sc = new Scanner(System.in);

        System.out.println("請輸入產品序列號");
        String planid = sc.next();
        for (int i = 0; i < planeInformation.length; i++) {
            if (planeInformation[i].getPlanid().equals(planid)) {

                if (planeInformation[i].getStatement() == 0) {
                    System.out.println("1.產品批次:" + planeInformation[i].getPlanid());
                    System.out.println("2.產品名稱:" + planeInformation[i].getPlanname());
                    System.out.println("3.計劃數量:" + planeInformation[i].getPlannumber());
                    planeInformation[i].setProcess(person[1].Theworkname);
                    System.out.println("4.當前工序:"+planeInformation[i].getProcess());
                    planeInformation[i].setNextprocess(person[2].Theworkname);

                    System.out.println("5.下一工序:"+planeInformation[i].getNextprocess());
                    planeInformation[i].setOperator(person[1].operator);
                    planeInformation[i].setRecipient(person[2].operator);
                    System.out.println("6.操作員:" + planeInformation[i].getOperator());
                    System.out.println("7.接收員:" + planeInformation[i].getRecipient());
                    System.out.println("8.上一道工序轉入數量:"+planeInformation[i].getInnumber());


                    System.out.println("9.轉出總數:");
                    int outnumber = sc.nextInt();
                    System.out.println("10.丟失數量:");
                    int missnumber = sc.nextInt();
                    System.out.println("11.廢品數量:");
                    int badnumber = sc.nextInt();
                    System.out.println("12.待檢驗數量:");
                    int inspectednubmer = sc.nextInt();

                    while (planeInformation[i].getInnumber() != outnumber + missnumber + badnumber + inspectednubmer) {
                        System.out.println("錄入錯誤資訊,請重新輸入以下資訊");
                        System.out.println("9.轉出總數:");
                        outnumber = sc.nextInt();
                        System.out.println("10.丟失數量:");
                        missnumber = sc.nextInt();
                        System.out.println("11.廢品數量:");
                        badnumber = sc.nextInt();
                        System.out.println("12.待檢驗數量:");
                        inspectednubmer = sc.nextInt();


                    }
                    System.out.println("選擇“Y”將修改資訊儲存提交。選擇“N”,不儲存修改資訊");
                    String yesno1 = sc.next();
                    if (yesno1.equals("Y")) {

                        planeInformation[i].setOutnumber(outnumber);
                        planeInformation[i].setMissnumber(missnumber);
                        planeInformation[i].setBadnumber(badnumber);
                        planeInformation[i].setInspectednubmer(inspectednubmer);
                        planeInformation[i].setStatement(1);
                        planeInformation[i].setId(idd);
                        System.out.println("提交成功");

                    }
                    break;


                } else if (planeInformation[i].getStatement() == 2) {
                    System.out.println("1.產品批次:" + planeInformation[i].getPlanid());
                    System.out.println("2.產品名稱:" + planeInformation[i].getPlanname());
                    System.out.println("3.計劃數量:" + planeInformation[i].getPlannumber());
                    System.out.println("4.當前工序:" + planeInformation[i].getProcess());
                    System.out.println("5.下一工序:" + planeInformation[i].getNextprocess());
                    System.out.println("6.操作員:" + planeInformation[i].getOperator());
                    System.out.println("7.接收員:" + planeInformation[i].getRecipient());
                    System.out.println("8.上一道工序轉入數量:" + planeInformation[i].getInnumber());
                    System.out.println("9.轉出總數:");
                    int outnumber = sc.nextInt();
                    System.out.println("10.丟失數量:");
                    int missnumber = sc.nextInt();
                    System.out.println("11.廢品數量:");
                    int badnumber = sc.nextInt();
                    System.out.println("12.待檢驗數量:");
                    int inspectednubmer = sc.nextInt();

                    while (planeInformation[i].getInnumber() != outnumber + missnumber + badnumber + inspectednubmer) {
                        System.out.println("錄入錯誤資訊,請重新輸入以下資訊");
                        System.out.println("9.轉出總數:");
                        outnumber = sc.nextInt();
                        System.out.println("10.丟失數量:");
                        missnumber = sc.nextInt();
                        System.out.println("11.廢品數量:");
                        badnumber = sc.nextInt();
                        System.out.println("12.待檢驗數量:");
                        inspectednubmer = sc.nextInt();


                    }
                    System.out.println("選擇“Y”將修改資訊儲存提交。選擇“N”,不儲存修改資訊");
                    String yesno1 = sc.next();
                    if (yesno1.equals("Y")) {

                        planeInformation[i].setOutnumber(outnumber);
                        planeInformation[i].setMissnumber(missnumber);
                        planeInformation[i].setBadnumber(badnumber);
                        planeInformation[i].setInspectednubmer(inspectednubmer);
                        planeInformation[i].setStatement(1);
                        System.out.println("提交成功");


                    }
                    break;
                }


            } else {
                System.out.println("庫中沒有該產品計劃");
            }
        }

    }

    public void Confirmreport() {
        Scanner sc = new Scanner(System.in);

        System.out.println("請輸入產品序列號");
        String planid = sc.next();
        for (int i = 0; i < planeInformation.length; i++) {
            if (planeInformation[i].getPlanid().equals(planid)) {
                if (planeInformation[i].getStatement() == 1) {
                    System.out.println("1.產品批次:" + planeInformation[i].getPlanid());
                    System.out.println("2.產品名稱:" + planeInformation[i].getPlanname());
                    System.out.println("3.計劃數量:" + planeInformation[i].getPlannumber());
                    System.out.println("4.當前工序:" + planeInformation[i].getProcess());
                    System.out.println("5.下一工序:" + planeInformation[i].getNextprocess());
                    System.out.println("6.操作員:" + planeInformation[i].getOperator());
                    System.out.println("7.接收員:" + planeInformation[i].getRecipient());
                    System.out.println("8.上一道工序轉入數量:" + planeInformation[i].getInnumber());
                    System.out.println("9.轉出總數:" + planeInformation[i].getOutnumber());
                    System.out.println("10.丟失數量:" + planeInformation[i].getMissnumber());
                    System.out.println("11.廢品數量:" + planeInformation[i].getBadnumber());
                    System.out.println("12.待檢驗數量:" + planeInformation[i].getInspectednubmer());
                    System.out.println("選擇Y/N來確認結果");
                    String yesno1 = sc.next();
                    if (yesno1.equals("Y")) {
                        planeInformation[i].setStatement(2);
                        planeInformation[i].setProcess(planeInformation[i].getNextprocess());
                        planeInformation[i].setOperator(planeInformation[i].getRecipient());
                        planeInformation[i].setInnumber(planeInformation[i].getOutnumber());
                        char x = planeInformation[i].getNextprocess().charAt(0);
                        int xx = x - '0';
                        planeInformation[i].setNextprocess(person[xx + 1].getTheworkname());
                        planeInformation[i].setRecipient(person[xx + 1].getOperator());
                        System.out.println("確認成功");



                    }
                    System.out.println("1.產品批次:" + planeInformation[i].getPlanid());
                    System.out.println("2.產品名稱:" + planeInformation[i].getPlanname());
                    System.out.println("3.計劃數量:" + planeInformation[i].getPlannumber());
                    System.out.println("4.當前工序:" + planeInformation[i].getProcess());
                    System.out.println("5.下一工序:" + planeInformation[i].getNextprocess());
                    System.out.println("6.操作員:" + planeInformation[i].getOperator());
                    System.out.println("7.接收員:" + planeInformation[i].getRecipient());
                    System.out.println("8.上一道工序轉入數量:" + planeInformation[i].getInnumber());
                    System.out.println("9.轉出總數:" + planeInformation[i].getOutnumber());
                    System.out.println("10.丟失數量:" + planeInformation[i].getMissnumber());
                    System.out.println("11.廢品數量:" + planeInformation[i].getBadnumber());
                    System.out.println("12.待檢驗數量:" + planeInformation[i].getInspectednubmer());
                    break;


                }
                else {
                    System.out.println("請先提交日報");
                    break;
                }
            }

        }

    }

    public void Statisticprogress() {
        Scanner sc = new Scanner(System.in);

        System.out.println("請輸入產品序列號");
        String planid = sc.next();
        for (int i = 0; i < planeInformation.length; i++) {
            if (planeInformation[i].getPlanid().equals(planid)) {

                System.out.println("1.產品批次:" + planeInformation[i].getPlanid());
                System.out.println("2.產品名稱:"+planeInformation[i].getPlanname());
                System.out.println("3.計劃數量:"+planeInformation[i].getPlannumber());
                char x = planeInformation[i].getProcess().charAt(0);
                int xx = x - '0';

                if(xx==0)
                {
                    System.out.println("4.完成數量:"+planeInformation[i].getOutnumber());
                    System.out.println("5.剩餘數量"+(planeInformation[i].getPlannumber()-planeInformation[i].getOutnumber()));
                }
                else
                {
                    System.out.println("4.完成數量:"+0);
                    System.out.println("5.剩餘數量"+(planeInformation[i].getPlannumber()));

                }




                break;

            }

        }
    }
}