第一次测试修改后代码

发布时间 2023-09-14 20:08:15作者: leapss

软件包study

//包内java类   Main.class

package study;

import java.util.Objects;
import java.util.Scanner;

public abstract class Main {

    static WarehouseInformation[] wh = new WarehouseInformation[5];
    static int i=0;

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        wh[0] = new WarehouseInformation();
        wh[1] = new WarehouseInformation();
        wh[2] = new WarehouseInformation();
        wh[3] = new WarehouseInformation();
        wh[4] = new WarehouseInformation();


        boolean flag = true;
        while (flag) {

            menu();
            String ch = sc.nextLine();

            switch (ch) {

                case "1":
                    commodity_inbound();
                    break;

                case "2":
                    i=0;
                    modification();
                    break;

                case "3":
                    i=0;
                    commodity_outbound();
                    break;

                case "4":
                    i=0;
                    inventory();
                    break;

                case "5":
                    flag=false;
                    break;

                default:
                    System.out.println("选项不存在,请重新输入:");

            }

        }

    }


    //菜单
    public static void menu() {
        System.out.println("***********************************************************");

        System.out.println("              石家庄铁道大学前进22软件开发有限公司");

        System.out.println("                  仓库管理系统2022版");

        System.out.println("***********************************************************");

        System.out.println("                    1、商品入库管理");

        System.out.println("                    2、商品信息修改");

        System.out.println("                    3、商品出库管理");

        System.out.println("                    4、仓库盘点管理");

        System.out.println("                    5、退出");

        System.out.println("**********************************************************");
    }

    //入库
    public static void commodity_inbound() {

        boolean sign = true;
        String Itemno = null, Itemname, Suppliername, Warehousingtime = null, Warehousenumber = null, Warehouseplace = null;
        int Itemnumber = 0;
        while (sign) {

            System.out.println("***********************************************************");
            System.out.println("              石家庄铁道大学前进22软件开发有限公司");
            System.out.println("                  仓库管理系统2022版");
            System.out.println("***********************************************************");


            System.out.print("                 商品编号:");
            boolean flag = true;
            while (flag) {
                Itemno = sc.nextLine();
                if (Itemno.length() != 8) {
                    System.out.println("录入错误!");
                    System.out.print("                 商品编号:");
                } else flag = false;
            }



            System.out.print("                 商品名称:");
            Itemname = sc.nextLine();




            System.out.print("                 供货商信息:");
            Suppliername = sc.nextLine();




            System.out.print("                 入库时间:");
            flag = true;
            while (flag) {
                Warehousingtime = sc.nextLine();
                if (Warehousingtime.length() != 8) {
                    System.out.println("录入错误!");
                    System.out.print("                 入库时间:");
                } else flag = false;
            }




            System.out.print("                 存放仓库号:");
            flag = true;
            while (flag) {
                Warehousenumber = sc.nextLine();
                if (Warehousenumber.length() != 3) {
                    System.out.println("录入错误!");
                    System.out.print("                 存放仓库号:");
                } else flag = false;
            }




            System.out.print("                 存放位置信息:");
            flag = true;
            while (flag) {
                Warehouseplace = sc.nextLine();
                if (Warehouseplace.length() != 8) {
                    System.out.println("录入错误!");
                    System.out.print("                 存放位置信息:");
                } else flag = false;
            }





            System.out.print("                 入库商品数量:");
            Itemnumber = sc.nextInt();
            String useless=sc.nextLine();





            System.out.print("              该商品入库操作已完成,是否提交(Y/N):");
            String s = sc.nextLine();
            if (Objects.equals(s, "Y") || Objects.equals(s, "y")) {
                wh[i].setItemno(Itemno);
                wh[i].setItemname(Itemname);
                wh[i].setSuppliername(Suppliername);
                wh[i].setWarehousingtime(Warehousingtime);
                wh[i].setWarehousenumber(Warehousenumber);
                wh[i].setWarehouseplace(Warehouseplace);
                wh[i].setItemnumber(Itemnumber);
                i++;
                System.out.println("输入完成");
                sign = false;
            } else if (Objects.equals(s, "N") || Objects.equals(s, "n")) System.out.println("请重新输入");
        }
    }

    //修改
    public static void modification() {

        while (true) {

            System.out.println("***********************************************************");

            System.out.println("              石家庄铁道大学前进22软件开发有限公司");

            System.out.println("                  仓库管理系统2022版");

            System.out.println("***********************************************************");

            System.out.print("                请输入商品编号:");
            String s = sc.nextLine();

            System.out.println("***********************************************************");



            if(Objects.equals(s, "-1"))  break;

            int a = 0, i = 0;
            for (i = 0; i < wh.length; i++) {
                if (Objects.equals(s, wh[i].getItemno())) {
                    a = 1;
                    break;
                }
            }

            if (a == 0) System.out.println("库中没有该商品");

            else if (a == 1) {

                boolean sign = true;
                while (sign) {
                    String Itemno = null, Itemname, Suppliername, Warehousingtime = null, Warehousenumber = null, Warehouseplace = null;
                    int Itemnumber;

                    display(i);
                    System.out.print("             请选择需要修改的信息编号(1-7):");
                    int choose = sc.nextInt();
                    String useless=sc.nextLine();


                    switch (choose) {

                        case 1: {

                            System.out.print("             请输入修改后的商品编号:");

                            boolean flag = true;
                            while (flag) {
                                Itemno = sc.nextLine();
                                System.out.println("***********************************************************");

                                if (Itemno.length() != 8) {
                                    System.out.println("录入错误!");
                                    System.out.print("             请输入修改后的商品编号:");
                                } else flag = false;
                            }

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                                wh[i].setItemno(Itemno);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        case 2: {

                            System.out.print("             请输入修改后的商品名称:");
                            Itemname = sc.nextLine();
                            System.out.println("***********************************************************");

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                                wh[i].setItemname(Itemname);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        case 3: {

                            System.out.print("             请输入修改后的供货商信息:");
                            Suppliername = sc.nextLine();
                            System.out.println("***********************************************************");

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")){
                                wh[i].setSuppliername(Suppliername);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        case 4: {

                            System.out.print("             请输入修改后的入库时间:");


                            boolean flag = true;
                            while (flag) {
                                Warehousingtime = sc.nextLine();
                                System.out.println("***********************************************************");

                                if (Warehousingtime.length() != 8) {
                                    System.out.println("录入错误!");
                                    System.out.print("             请输入修改后的入库时间:");
                                } else flag = false;
                            }

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                                wh[i].setWarehousingtime(Warehousingtime);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }

                        case 5: {

                            System.out.print("             请输入修改后的存放仓库号:");

                            boolean flag = true;
                            while (flag) {
                                Warehousenumber = sc.nextLine();
                                System.out.println("***********************************************************");

                                if (Warehousenumber.length() != 3) {
                                    System.out.println("录入错误!");
                                    System.out.print("             请输入修改后的存放仓库号:");
                                } else flag = false;
                            }

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                                wh[i].setWarehousingtime(Warehousenumber);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        case 6: {

                            System.out.print("             请输入修改后的存放位置信息:");

                            boolean flag = true;
                            while (flag) {
                                Warehouseplace = sc.nextLine();
                                System.out.println("***********************************************************");

                                if (Warehouseplace.length() != 8) {
                                    System.out.println("录入错误!");
                                    System.out.print("             请输入修改后的存放位置信息:");
                                } else flag = false;
                            }

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")){
                                wh[i].setWarehouseplace(Warehouseplace);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        case 7: {

                            System.out.print("             请输入修改后的入库商品数量:");
                            Itemnumber = sc.nextInt();
                            System.out.println("***********************************************************");

                            System.out.println("该商品信息修改操作已完成,是否提交(Y/N)");
                            String c=sc.nextLine();
                            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                                wh[i].setItemnumber(Itemnumber);
                                System.out.println("修改完成");
                            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                                System.out.println("放弃修改");
                            }
                            break;
                        }


                        default: {
                            System.out.println("该选项不存在");
                            sign=false;
                        }
                    }
                }

            }
        }
    }

    //出库
    public static void commodity_outbound() {
        System.out.println("***********************************************************");

        System.out.println("              石家庄铁道大学前进22软件开发有限公司");

        System.out.println("                  仓库管理系统2022版");

        System.out.println("***********************************************************");

        System.out.print("                 请输入商品编号:");
        String s = sc.nextLine();

        System.out.println("***********************************************************");


        int a = 0, i = 0;
        for (i = 0; i < wh.length; i++) {
            if (Objects.equals(s, wh[i].getItemno())) {
                a = 1;
                break;
            }
        }

        if (a == 0) System.out.println("库中没有该商品");

        else if (a == 1) {

           display(i);

            String shipmenttime = null;
            int outnumber=0;


            System.out.print("                 出库时间:");
            boolean flag = true;
            while (flag) {
                shipmenttime = sc.nextLine();
                if (shipmenttime.length() != 8) {
                    System.out.println("录入错误!");
                    System.out.print("                 出库时间:");
                }else if(shipmenttime.compareTo(wh[i].getWarehousingtime())<=0){
                    System.out.println("录入错误!");
                    System.out.print("                 出库时间:");
                }else flag = false;
            }

            System.out.print("                 出库商品数量:");
            flag = true;
            while (flag) {
                outnumber = sc.nextInt();
                String useless=sc.nextLine();
                if(outnumber>wh[i].getItemnumber()){
                    System.out.println("录入错误!");
                    System.out.print("                 出库商品数量:");
                }else flag = false;
            }

            System.out.println("***********************************************************");

            System.out.print("              该商品出库操作已完成,是否提交(Y/N):");
            String c = sc.nextLine();
            if (Objects.equals(c, "Y") || Objects.equals(c, "y")) {
                wh[i].setShipmenttime(shipmenttime);
                wh[i].setOutnumber(outnumber);
                System.out.println("保存完成");
                //sign=false;
            } else if (Objects.equals(c, "N") || Objects.equals(c, "n")) {
                System.out.println("放弃保存");
            }
        }
    }

    //输出
    public static void inventory(){
        System.out.println("***********************************************************");

        System.out.println("              石家庄铁道大学前进22软件开发有限公司");

        System.out.println("                  仓库管理系统2022版");

        System.out.println("***********************************************************");
        for(int i=0;i< wh.length;i++){
            System.out.println("商品编号:"+wh[i].getItemno()+"、商品名称"+wh[i].getItemname()+"、库存数量"+(wh[i].getItemnumber()-wh[i].getOutnumber()));
        }
        System.out.println("***********************************************************");
    }

    public static void display(int i){
        System.out.println("***********************************************************");

        System.out.println("              石家庄铁道大学前进22软件开发有限公司");

        System.out.println("                  仓库管理系统2022版");

        System.out.println("***********************************************************");

        System.out.print("                 商品编号:");
        System.out.println(wh[i].getItemno());

        System.out.print("                 商品名称:");
        System.out.println(wh[i].getItemname());

        System.out.print("                 供货商信息:");
        System.out.println(wh[i].getSuppliername());

        System.out.print("                 入库时间:");
        System.out.println(wh[i].getWarehousingtime());

        System.out.print("                 存放仓库号:");
        System.out.println(wh[i].getWarehousenumber());

        System.out.print("                 存放位置信息:");
        System.out.println(wh[i].getWarehouseplace());

        System.out.print("                 入库商品数量:");
        System.out.println(wh[i].getItemnumber());


    }

}
//包内java类 WarehouseInformation.class

package study;

public class WarehouseInformation {
    private String itemno ;             //商品编号

    private String itemname ;           //商品名称

    private String suppliername;        //供货商名称

    private String warehousingtime;     //入库时间

    private String shipmenttime;        //出库时间

    private String warehousenumber;     //仓库编号

    private String warehouseplace;      //商品的具体位置

    private int itemnumber;             //入库数量

    private int outnumber;              //出库数量

    public WarehouseInformation(){
        this.itemno = " ";
        this.itemname = " ";
        this.suppliername = " ";
        this.warehousingtime = " ";
        this.shipmenttime = " ";
        this.warehousenumber = " ";
        this.warehouseplace = " ";
        this.itemnumber = 0 ;
        this.outnumber = 0 ;
    }
    public WarehouseInformation(String itemno, String itemname, String suppliername, String warehousingtime, String shipmenttime, String warehousenumber, String warehouseplace, int itemnumber, int outnumber) {
        this.itemno = itemno;
        this.itemname = itemname;
        this.suppliername = suppliername;
        this.warehousingtime = warehousingtime;
        this.shipmenttime = shipmenttime;
        this.warehousenumber = warehousenumber;
        this.warehouseplace = warehouseplace;
        this.itemnumber = itemnumber;
        this.outnumber = outnumber;
    }


    public String getItemno() {
        return itemno;
    }

    public void setItemno(String itemno) {
        this.itemno = itemno;
    }

    public String getItemname() {
        return itemname;
    }

    public void setItemname(String itemname) {
        this.itemname = itemname;
    }

    public String getSuppliername() {
        return suppliername;
    }

    public void setSuppliername(String suppliername) {
        this.suppliername = suppliername;
    }

    public String getWarehousingtime() {
        return warehousingtime;
    }

    public void setWarehousingtime(String warehousingtime) {
        this.warehousingtime = warehousingtime;
    }

    public String getShipmenttime() {
        return shipmenttime;
    }

    public void setShipmenttime(String shipmenttime) {
        this.shipmenttime = shipmenttime;
    }

    public String getWarehousenumber() {
        return warehousenumber;
    }

    public void setWarehousenumber(String warehousenumber) {
        this.warehousenumber = warehousenumber;
    }

    public String getWarehouseplace() {
        return warehouseplace;
    }

    public void setWarehouseplace(String warehouseplace) {
        this.warehouseplace = warehouseplace;
    }

    public int getItemnumber() {
        return itemnumber;
    }

    public void setItemnumber(int itemnumber) {
        this.itemnumber = itemnumber;
    }

    public int getOutnumber() {
        return outnumber;
    }

    public void setOutnumber(int outnumber) {
        this.outnumber = outnumber;
    }
}