课后作业-重写测试

修改后的代码如下

主方法

import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        WarehouseManagement sys=new WarehouseManagement();
        WarehouseInformation a=new WarehouseInformation("11111111","ada","bbb","20001001","","111","11111111",300,0);
        WarehouseInformation b=new WarehouseInformation("22222222","bdasdh","vbv","20101010","","111","11111111",450,0);
        WarehouseInformation c=new WarehouseInformation("11111111","aaa","bbb","20001001","","111","11111111",250,0);
        WarehouseInformation d=new WarehouseInformation("22222222","bbb","vasd","20001001","","111","11111111",200,0);
        WarehouseInformation e=new WarehouseInformation("33333333","aaa","bbb","20001001","","111","11111111",200,0);
        sys.inf.add(a);
        sys.inf.add(b);
        sys.inf.add(c);
        sys.inf.add(d);
        sys.inf.add(e);
        while (true) {
            System.out.println("***********************************************************");
            System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
            System.out.println("\t\t仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("\t\t1、商品入库管理");
            System.out.println("\t\t2、商品信息修改");
            System.out.println("\t\t3、商品出库管理");
            System.out.println("\t\t4、仓库盘点管理");
            System.out.println("***********************************************************");
            Scanner sc=new Scanner(System.in);
            int choice = sc.nextInt();
            switch (choice){
                case 1->{
                    sys.goodsWarehousing();
                }
                case 2->{
                    sys.modifyWarehouse();
                }
                case 3->{
                    sys.outboundWarehouse();
                }
                case 4->{
                    sys.countGoods();
                }
                default -> {
                    System.out.println("该选项不存在!");
                }
            }
        }
    }
}
WarehouseInformation类
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() {
    }

    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;
    }
}
WarehouseManagement类
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class WarehouseManagement {
    public WarehouseManagement() {

    }

    public  ArrayList<WarehouseInformation> inf=new ArrayList<WarehouseInformation>();
    public  void  goodsWarehousing(){
        Scanner sc=new Scanner(System.in);
         String itemNO;
         String itemname;
         String suppliername;
         String warehousingtime;
         //String shipmenttime;
         String warehousenumber;
         String warehouseplace;
         int itemnumber;
         //int outnumber;
        while (true){
            System.out.println("***********************************************************");
            System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
            System.out.println("\t\t仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.println("\t\t请输入商品的入库信息");
            System.out.print("\t\t商品编号:");
            itemNO=sc.next();
            if(itemNO.length()==8){
                for(int i=0;i<itemNO.length();i++){
                    if(itemNO.charAt(i)>'9'||itemNO.charAt(i)<'0'){
                        System.out.println("格式错误");
                        continue;
                    }
                }
            }else{
                System.out.println("格式错误");
                continue;
            }
            System.out.print("商品名称:");
            itemname=sc.next();
            System.out.print("供货商信息:");
            suppliername=sc.next();
            System.out.print("入库时间:");
            warehousingtime=sc.next();
            if(warehousingtime.length()==8){
                for(int i=0;i<warehousingtime.length();i++){
                    if(warehousingtime.charAt(i)>'9'||warehousingtime.charAt(i)<'0'){
                        System.out.println("格式错误");
                        continue;
                    }
                }
            }else{
                System.out.println("格式错误");
                continue;
            }
            System.out.print("存放仓库号:");
            warehousenumber=sc.next();
            if(warehousenumber.length()==3){
                for(int i=0;i<warehousenumber.length();i++){
                    if(warehousenumber.charAt(i)>'9'||warehousenumber.charAt(i)<'0'){
                        System.out.println("格式错误");
                        continue;
                    }
                }
            }else{
                System.out.println("格式错误");
                continue;
            }
            System.out.print("存放位置信息:");
            warehouseplace=sc.next();
            if(warehouseplace.length()==8){
                for(int i=0;i<warehouseplace.length();i++){
                    if(warehouseplace.charAt(i)>'9'||warehouseplace.charAt(i)<'0'){
                        System.out.println("格式错误");
                        continue;
                    }
                }
            }else{
                System.out.println("格式错误");
                continue;
            }
            System.out.println("入库商品数量:");
            itemnumber=sc.nextInt();
            System.out.println("\t该商品入库操作已完成,是否提交(Y/N)");
            System.out.println("**********************************************************");
            String cho;
            while (true){
                cho=sc.next();
                if(cho.equals("Y")||cho.equals("y")){
                    WarehouseInformation wi=new WarehouseInformation(itemNO,itemname,suppliername,warehousingtime,"",warehousenumber,warehouseplace,itemnumber,0);
                    inf.add(wi);
                    return;
                }else if(cho.equals("N")||cho.equals("n")){
                    goodsWarehousing();
                    return;
                }
            }
        }
    }
    public void modifyWarehouse(){
        Scanner sc=new Scanner(System.in);

        int index=0;
        while(true) {
            System.out.println("***********************************************************");
            System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
            System.out.println("\t\t仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.print("\t\t请输入商品编号:");
            String  itemNO=sc.next();
            System.out.println("***********************************************************");
            boolean flag=false;//标记有没有找到该商品编号
            for (int i = 0; i < inf.size(); i++) {
                if(inf.get(i).getItemNO().equals(itemNO)){
                    flag=true;
                    index=i;
                    break;
                }
            }
            if(flag==true){
                break;
            }else {
                System.out.println("库中没有该商品");
            }
        }

        System.out.println("***********************************************************");
        System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
        System.out.println("\t\t仓库管理系统2022版");
        System.out.println("***********************************************************");
        System.out.println("1、商品编号:"+inf.get(index).getItemNO());
        System.out.println("2、商品名称:"+inf.get(index).getItemname());
        System.out.println("3、供货商信息:"+inf.get(index).getSuppliername());
        System.out.println("4、入库时间:"+inf.get(index).getWarehousingtime());
        System.out.println("5、存放仓库号:"+inf.get(index).getWarehousenumber());
        System.out.println("6、存放位置信息:"+inf.get(index).getWarehouseplace());
        System.out.println("7、入库商品数量:"+inf.get(index).getItemnumber());
        String itemNO=inf.get(index).getItemNO();
        String Itemname=inf.get(index).getItemname();
        String Suppliername=inf.get(index).getSuppliername();
        String Warehousingtime=inf.get(index).getWarehousingtime();
        String  Warehouseplace=inf.get(index).getWarehouseplace();
        String  Warehousenumber=inf.get(index).getWarehousenumber();
        int  Itemnumber=inf.get(index).getItemnumber();
        System.out.print("请选择需要修改的信息编号(1-7):");
        int cho=sc.nextInt();
        switch (cho){
            case 1->{

                while(true) {

                    System.out.print("请输入修改后的商品编号:");
                    itemNO = sc.next();
                    if (itemNO.length() == 8) {
                        boolean flag=false;
                        for (int i = 0; i < itemNO.length(); i++) {
                            if (itemNO.charAt(i) > '9' || itemNO.charAt(i) < '0') {
                                System.out.println("格式错误");
                                flag=true;
                                break;
                            }
                        }
                        if(!flag){
                            break;
                        }

                    } else {
                        System.out.println("格式错误");
                    }
                }

            }
            case 2->{
                System.out.print("请输入修改后的商品名称:");
                Itemname=sc.next();
            }
            case 3->{
                System.out.print("请输入修改后的供货商信息:");
                Suppliername=sc.next();
            }
            case 4->{

                while(true) {

                    System.out.print("请输入修改后的商品入库时间:");
                    Warehousingtime = sc.next();
                    if (Warehousingtime.length() == 8) {
                        boolean flag=false;
                        for (int i = 0; i < Warehousingtime.length(); i++) {
                            if (Warehousingtime.charAt(i) > '9' || Warehousingtime.charAt(i) < '0') {
                                System.out.println("格式错误");
                                flag=true;
                                break;
                            }
                        }
                        if(!flag){
                            break;
                        }

                    } else {
                        System.out.println("格式错误");
                    }
                }
            }
            case 5->{

                while(true) {

                    System.out.print("请输入修改后的存放仓库号:");
                    Warehousenumber = sc.next();
                    if (Warehousenumber.length() == 3) {
                        boolean flag=false;
                        for (int i = 0; i < Warehousenumber.length(); i++) {
                            if (Warehousenumber.charAt(i) > '9' || Warehousenumber.charAt(i) < '0') {
                                System.out.println("格式错误");
                                flag=true;
                                break;
                            }
                        }
                        if(!flag){
                            break;
                        }

                    } else {
                        System.out.println("格式错误");
                    }
                }
            }
            case 6->{

                while(true) {

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

                    Warehouseplace = sc.next();
                    if (Warehouseplace.length() == 8) {
                        boolean flag=false;
                        for (int i = 0; i < Warehouseplace.length(); i++) {
                            if (Warehouseplace.charAt(i) > '9' || Warehouseplace.charAt(i) < '0') {
                                System.out.println("格式错误");
                                flag=true;
                                break;
                            }
                        }
                        if(!flag){
                            break;
                        }

                    } else {
                        System.out.println("格式错误");
                    }
                }

            }
            case 7->{
                System.out.print("请输入修改后的入库商品数量:");
                Itemnumber=sc.nextInt();
            }
            default -> {
                System.out.println("该选项不存在!");
                return;
            }
        }
        System.out.println("***********************************************************");
        String choice;
        while(true){
            System.out.println("是否保存并返回主菜单?(Y/N)");
            choice=sc.next();
            if(choice.equals("Y")||choice.equals("y")){
                inf.get(index).setItemNO(itemNO);
                inf.get(index).setItemnumber(Itemnumber);
                inf.get(index).setWarehouseplace(Warehouseplace);
                inf.get(index).setWarehousenumber(Warehousenumber);
                inf.get(index).setWarehousingtime(Warehousingtime);
                inf.get(index).setSuppliername(Suppliername);
                inf.get(index).setItemname(Itemname);
                return;
            }else if(choice.equals("N")||choice.equals("n")){
                modifyWarehouse();
                return;
            }
        }
    }
    public void outboundWarehouse(){
        Scanner sc=new Scanner(System.in);

        int index=0;
        while(true) {
            System.out.println("***********************************************************");
            System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
            System.out.println("\t\t仓库管理系统2022版");
            System.out.println("***********************************************************");
            System.out.print("\t\t请输入商品编号:");
            String  itemNO=sc.next();
            System.out.println("***********************************************************");
            boolean flag=false;//标记有没有找到该商品编号
            for (int i = 0; i < inf.size(); i++) {
                if(inf.get(i).getItemNO().equals(itemNO)){
                    flag=true;
                    index=i;
                    break;
                }
            }
            if(flag==true){
                break;
            }else {
                System.out.println("库中没有该商品");
            }
        }
        System.out.println("***********************************************************");
        System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
        System.out.println("\t\t仓库管理系统2022版");
        System.out.println("***********************************************************");
        System.out.println("1、商品编号:"+inf.get(index).getItemNO());
        System.out.println("2、商品名称:"+inf.get(index).getItemname());
        System.out.println("3、供货商信息:"+inf.get(index).getSuppliername());
        System.out.println("4、入库时间:"+inf.get(index).getWarehousingtime());
        System.out.println("5、存放仓库号:"+inf.get(index).getWarehousenumber());
        System.out.println("6、存放位置信息:"+inf.get(index).getWarehouseplace());
        System.out.println("7、入库商品数量:"+inf.get(index).getItemnumber());
        System.out.print("出库时间:");
        String time;
        String foretime=inf.get(index).getWarehousingtime();
        while(true){
            time=sc.next();
            if(time.length()==8){
                boolean flag=true;
                for(int i=0;i<time.length();i++){
                    if(time.charAt(i)>'9'||time.charAt(i)<'0'){
                        flag=false;
                    }
                }
                if(flag) {
                    int year1 = 0, month1 = 0, day1 = 0;
                    year1 = (time.charAt(0) - '0') * 1000 + (time.charAt(1) - '0') * 100 + (time.charAt(2) - '0') * 10 + (time.charAt(3) - '0');
                    month1 = ((time.charAt(4) - '0') * 10 + (time.charAt(5) - '0'));
                    day1=((time.charAt(6) - '0') * 10 + (time.charAt(7) - '0'));
                    int year2 = 0, month2 = 0, day2 = 0;
                    year2 = (foretime.charAt(0) - '0') * 1000 + (foretime.charAt(1) - '0') * 100 + (foretime.charAt(2) - '0') * 10 + (foretime.charAt(3) - '0');
                    month2 = ((foretime.charAt(4) - '0') * 10 + (foretime.charAt(5) - '0'));
                    day2=((foretime.charAt(6) - '0') * 10 + (foretime.charAt(7) - '0'));
                    if(year2<year1){
                        flag=true;
                    }else if(year2==year1){
                        if(month1>month2){
                            flag=true;
                        }else if(month1==month2){
                            if(day1>day2){
                                flag=true;
                            }else {
                                flag=false;
                            }
                        }else{
                            flag=false;
                        }
                    }else {
                        flag=false;
                    }
                }
                if (flag) {
                   break;

                }else {
                    System.out.print("输入错误!请重新输入:");
                }
            }
        }
        System.out.print("出库数量:");
        int num;
        while (true){
            num=sc.nextInt();
            if(num<inf.get(index).getItemnumber()){
                break;
            }else{
                System.out.print("输入错误!请重新输入:");
            }
        }
        String choice;
        while(true){
            System.out.println("是否保存并返回主菜单?(Y/N)");
            choice=sc.next();
            if(choice.equals("Y")||choice.equals("y")){
                inf.get(index).setShipmenttime(time);
                inf.get(index).setOutnumber(num);
                return;
            }else if(choice.equals("N")||choice.equals("n")){
                outboundWarehouse();
                return;
            }
        }
    }
    public void countGoods(){
        System.out.println("***********************************************************");
        System.out.println("\t石家庄铁道大学前进22软件开发有限公司");
        System.out.println("\t\t仓库管理系统2022版");
        System.out.println("***********************************************************");
        int cnt=1;
        for (int i = 0; i < inf.size(); i++) {
            System.out.println(cnt+"、\t商品编号"+inf.get(i).getItemNO()+"、商品名称:"+inf.get(i).getItemname()+"、库存数量"+(inf.get(i).getItemnumber()-inf.get(i).getOutnumber()));
        }
        System.out.println("***********************************************************");

    }
}

 

posted on 2023-09-16 11:06  Daniel350  阅读(9)  评论(0编辑  收藏  举报