首页 > 其他分享 >2024/9/27

2024/9/27

时间:2024-09-27 23:02:44浏览次数:7  
标签:27 scanner String System 2024 item println out

public class WarehouseInformation {
private String itemnumber;
private String itemname;
private String suppliername;
private String warehousingtime;
private String shipmenttime;
private String warehousenumber;
private String warehouseplace;
private int itemnumberQuantity;
private int outnumber;

// Constructor
public WarehouseInformation(String itemnumber, String itemname, String suppliername,
                            String warehousingtime, String shipmenttime, String warehousenumber,
                            String warehouseplace, int itemnumberQuantity, int outnumber) {
    this.itemnumber = itemnumber;
    this.itemname = itemname;
    this.suppliername = suppliername;
    this.warehousingtime = warehousingtime;
    this.shipmenttime = shipmenttime;
    this.warehousenumber = warehousenumber;
    this.warehouseplace = warehouseplace;
    this.itemnumberQuantity = itemnumberQuantity;
    this.outnumber = outnumber;
}

// Getters and Setters
public String getItemnumber() { return itemnumber; }
public void setItemnumber(String itemnumber) { this.itemnumber = itemnumber; }

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 getItemnumberQuantity() { return itemnumberQuantity; }
public void setItemnumberQuantity(int itemnumberQuantity) { this.itemnumberQuantity = itemnumberQuantity; }

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

}

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
private ArrayList warehouseList = new ArrayList<>();

public void mainMenu() {
    Scanner scanner = new Scanner(System.in);
    while (true) {
        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("***********************************************************");
        System.out.print("请输入选项(1-4):");
        int choice = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        switch (choice) {
            case 1:
                manageWarehouseEntry(scanner);
                break;
            case 2:
                modifyItemInfo(scanner);
                break;
            case 3:
                manageWarehouseExit(scanner);
                break;
            case 4:
                inventoryCheck();
                break;
            default:
                System.out.println("该选项不存在!");
                break;
        }
    }
}

private void manageWarehouseEntry(Scanner scanner) {
    System.out.println("***********************************************************");
    System.out.println("商品入库管理");
    System.out.println("***********************************************************");

    String itemnumber, itemname, suppliername, warehousingtime, shipmenttime, warehousenumber, warehouseplace;
    int itemnumberQuantity;

    while (true) {
        System.out.print("请输入商品编号(8位数字):");
        itemnumber = scanner.nextLine();
        if (itemnumber.matches("\\d{8}")) break;
        System.out.println("录入错误,请重新输入商品编号!");
    }

    System.out.print("请输入商品名称:");
    itemname = scanner.nextLine();

    System.out.print("请输入供货商信息:");
    suppliername = scanner.nextLine();

    while (true) {
        System.out.print("请输入入库时间(YYYYMMDD):");
        warehousingtime = scanner.nextLine();
        if (warehousingtime.matches("\\d{8}")) break;
        System.out.println("录入错误,请重新输入入库时间!");
    }

    System.out.print("请输入存放仓库号(3位):");
    warehousenumber = scanner.nextLine();
    if (!warehousenumber.matches("\\d{3}")) {
        System.out.println("录入错误,请重新输入仓库号!");
        return;
    }

    System.out.print("请输入存放位置信息(8位):");
    warehouseplace = scanner.nextLine();
    if (!warehouseplace.matches("\\d{8}")) {
        System.out.println("录入错误,请重新输入存放位置信息!");
        return;
    }

    System.out.print("请输入入库商品数量:");
    itemnumberQuantity = scanner.nextInt();
    scanner.nextLine(); // Consume newline

    System.out.println("***********************************************************");
    System.out.println("商品编号:" + itemnumber);
    System.out.println("商品名称:" + itemname);
    System.out.println("供货商信息:" + suppliername);
    System.out.println("入库时间:" + warehousingtime);
    System.out.println("存放仓库号:" + warehousenumber);
    System.out.println("存放位置信息:" + warehouseplace);
    System.out.println("入库商品数量:" + itemnumberQuantity);
    System.out.println("该商品入库操作已完成,是否提交(Y/N):");

    String submit = scanner.nextLine();
    if (submit.equalsIgnoreCase("Y")) {
        WarehouseInformation info = new WarehouseInformation(itemnumber, itemname, suppliername, warehousingtime, "", warehousenumber, warehouseplace, itemnumberQuantity, 0);
        warehouseList.add(info);
        System.out.println("商品信息已保存!");
    } else {
        System.out.println("商品信息未保存!");
    }
}

private void modifyItemInfo(Scanner scanner) {
    System.out.println("***********************************************************");
    System.out.println("商品信息修改");
    System.out.println("***********************************************************");

    while (true) {
        System.out.print("请输入商品编号(8位数字):");
        String itemnumber = scanner.nextLine();
        if (!itemnumber.matches("\\d{8}")) {
            System.out.println("录入错误,请重新输入商品编号!");
            continue;
        }

        WarehouseInformation item = findItemByNumber(itemnumber);
        if (item == null) {
            System.out.println("库中没有该商品!");
            return;
        }

        System.out.println("***********************************************************");
        System.out.println("1、商品编号:" + item.getItemnumber());
        System.out.println("2、商品名称:" + item.getItemname());
        System.out.println("3、供货商信息:" + item.getSuppliername());
        System.out.println("4、入库时间:" + item.getWarehousingtime());
        System.out.println("5、存放仓库号:" + item.getWarehousenumber());
        System.out.println("6、存放位置信息:" + item.getWarehouseplace());
        System.out.println("7、入库商品数量:" + item.getItemnumberQuantity());
        System.out.println("***********************************************************");
        System.out.print("请选择需要修改的信息编号(1-7):");
        int fieldToModify = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        switch (fieldToModify) {
            case 1:
                System.out.print("请输入新的商品编号:");
                itemnumber = scanner.nextLine();
                if (itemnumber.matches("\\d{8}")) item.setItemnumber(itemnumber);
                else System.out.println("录入错误,商品编号必须为8位数字!");
                break;
            case 2:
                System.out.print("请输入新的商品名称:");
                item.setItemname(scanner.nextLine());
                break;
            case 3:
                System.out.print("请输入新的供货商信息:");
                item.setSuppliername(scanner.nextLine());
                break;
            case 4:
                System.out.print("请输入新的入库时间(YYYYMMDD):");
                item.setWarehousingtime(scanner.nextLine());
                break;
            case 5:
                System.out.print("请输入新的存放仓库号(3位):");
                String warehousenumber = scanner.nextLine();
                if (warehousenumber.matches("\\d{3}")) item.setWarehousenumber(warehousenumber);
                else System.out.println("录入错误,仓库号必须为3位数字!");
                break;
            case 6:
                System.out.print("请输入新的存放位置信息(8位):");
                String warehouseplace = scanner.nextLine();
                if (warehouseplace.matches("\\d{8}")) item.setWarehouseplace(warehouseplace);
                else System.out.println("录入错误,存放位置信息必须为8位数字!");
                break;
            case 7:
                System.out.print("请输入新的入库商品数量:");
                item.setItemnumberQuantity(scanner.nextInt());
                scanner.nextLine(); // Consume newline
                break;
            default:
                System.out.println("该选项不存在!");
                return;
        }

        System.out.println("***********************************************************");
        System.out.println("商品编号:" + item.getItemnumber());
        System.out.println("商品名称:" + item.getItemname());
        System.out.println("供货商信息:" + item.getSuppliername());
        System.out.println("入库时间:" + item.getWarehousingtime());
        System.out.println("存放仓库号:" + item.getWarehousenumber());
        System.out.println("存放位置信息:" + item.getWarehouseplace());
        System.out.println("入库商品数量:" + item.getItemnumberQuantity());
        System.out.println("***********************************************************");
        System.out.println("是否保存修改(Y/N):");
        String saveChanges = scanner.nextLine();
        if (saveChanges.equalsIgnoreCase("Y")) {
            System.out.println("修改信息已保存!");
        } else {
            System.out.println("修改信息未保存!");
        }
    }
}

private void manageWarehouseExit(Scanner scanner) {
    System.out.println("***********************************************************");
    System.out.println("商品出库管理");
    System.out.println("***********************************************************");

    while (true) {
        System.out.print("请输入商品编号(8位数字):");
        String itemnumber = scanner.nextLine();
        if (!itemnumber.matches("\\d{8}")) {
            System.out.println("录入错误,请重新输入商品编号!");
            continue;
        }

        WarehouseInformation item = findItemByNumber(itemnumber);
        if (item == null) {
            System.out.println("库中没有该商品!");
            return;
        }

        System.out.println("***********************************************************");
        System.out.println("1、商品编号:" + item.getItemnumber());
        System.out.println("2、商品名称:" + item.getItemname());
        System.out.println("3、供货商信息:" + item.getSuppliername());
        System.out.println("4、入库时间:" + item.getWarehousingtime());
        System.out.println("5、存放仓库号:" + item.getWarehousenumber());
        System.out.println("6、存放位置信息:" + item.getWarehouseplace());
        System.out.println("7、入库商品数量:" + item.getItemnumberQuantity());
        System.out.println("***********************************************************");
        System.out.print("请输入出库时间(YYYYMMDD):");
        String shipmenttime = scanner.nextLine();
        System.out.print("请输入出库数量:");
        int outnumber = scanner.nextInt();
        scanner.nextLine(); // Consume newline

        if (outnumber > item.getItemnumberQuantity()) {
            System.out.println("出库数量不能超过入库数量!");
            return;
        }

        item.setShipmenttime(shipmenttime);
        item.setOutnumber(outnumber);

        System.out.println("***********************************************************");
        System.out.println("商品编号:" + item.getItemnumber());
        System.out.println("商品名称:" + item.getItemname());
        System.out.println("供货商信息:" + item.getSuppliername());
        System.out.println("入库时间:" + item.getWarehousingtime());
        System.out.println("存放仓库号:" + item.getWarehousenumber());
        System.out.println("存放位置信息:" + item.getWarehouseplace());
        System.out.println("入库商品数量:" + item.getItemnumberQuantity());
        System.out.println("出库时间:" + item.getShipmenttime());
        System.out.println("出库数量:" + item.getOutnumber());
        System.out.println("***********************************************************");
        System.out.println("是否保存出库信息(Y/N):");
        String saveChanges = scanner.nextLine();
        if (saveChanges.equalsIgnoreCase("Y")) {
            System.out.println("出库信息已保存!");
        } else {
            System.out.println("出库信息未保存!");
        }
    }
}

private void inventoryCheck() {
    System.out.println("***********************************************************");
    System.out.println("仓库盘点管理");
    System.out.println("***********************************************************");

    for (WarehouseInformation item : warehouseList) {
        int totalIn = item.getItemnumberQuantity();
        int totalOut = item.getOutnumber();
        int currentStock = totalIn - totalOut;

        System.out.println("商品编号:" + item.getItemnumber() + "、商品名称:" + item.getItemname() + "、库存数量:" + currentStock);
    }
}

private WarehouseInformation findItemByNumber(String itemnumber) {
    for (WarehouseInformation item : warehouseList) {
        if (item.getItemnumber().equals(itemnumber)) {
            return item;
        }
    }
    return null;
}

}

标签:27,scanner,String,System,2024,item,println,out
From: https://www.cnblogs.com/dengyizhidai/p/18436749

相关文章

  • 华为9.27笔试
    第一题给出员工(\(n\leq100\))和对应的亲属关系,询问能否将其分为两个组合,要求亲属不在同一侧。要求两个组合中第一个数尽量小。一眼并查集,即员工i的亲属属于同一个集合,生成一个集合编号j。记录员工i以及与之互斥的点,用于后续获取员工i互斥的集合编号j。由于要求组合中第一......
  • 2024.9.27
    枚举定义:定义了一个名为Size的枚举,包含三个常量:SMALL、MEDIUM和LARGE。枚举常量比较:s==t比较Size.SMALL和Size.LARGE,结果为false,因为它们是不同的枚举常量。检查是否为原始类型:s.getClass().isPrimitive()返回false,表明枚举类型不是原始类型,而是对象。使......
  • java动手动脑-2024/9/27
    publicclassEnumTest{publicstaticvoidmain(String[]args){Sizes=Size.SMALL;Sizet=Size.LARGE;//s和t引用同一个对象?System.out.println(s==t);////是原始数据类型吗?System.out.println(s.getClass().i......
  • 9.27
    因为昨天部署成功服务器,所以把云服务器关机了,但是当我再重启时,更换了公网IP,再进行重新打包时,前端便库库报错,这次搞了好久才搞好,所以总结一下前后端都需要改哪里。前端1、部署在云服务器上的前后端通信时,前端向后端通信时需要的是公网IP。 2、部署时需要修改nginx的配置......
  • 2024/9/27
    第一个输出:X和Y会被转换成字符串"100"和"200",然后与前面的字符串连接起来,输出结果将是:X+Y=100200第二个输出:X和Y首先被相加得到300,然后300与字符串"=X+Y"连接。由于300是一个整数,它会被转换成字符串"300",然后与后面的字符串连接起来,输出结果将是:300=X+Yimpor......
  • 【2024计算机毕业设计】基于jsp+mysql+Spring+mybatis的SSM在线装潢家装材料进销存管
    运行环境:最好是javajdk1.8,我在这个平台上运行的。其他版本理论上也可以。IDE环境:Eclipse,Myeclipse,IDEA或者SpringToolSuite都可以,如果编译器的版本太低,需要升级下编译器,不要弄太低的版本tomcat服务器环境:Tomcat7.x,8.x,9.x版本均可操作系统环境:WindowsXP/7......
  • 【2024.09.27】NOIP2024 赛前集训-刷题训练(3)
    【2024.09.27】NOIP2024赛前集训-刷题训练(3)「NOIP2018提高组」铺设道路算法一:模拟正常人铺路的过程,每次找区间的最小值,最小值就是本次填的高度,由于出现了若干个0位置,就分裂成若干个子区间去重复上述过程,直到全部变成0。时间复杂度\(O(nlogn)\),瓶颈在预处理st表。算法二:若......
  • 2024/9/27日工作日志
    复习英语单词60个;完成数据结构pta选择题,函数第一题;includeincludeincludeincludeusingnamespacestd;defineOVERFLOW-2typedefintElemType;//ElemType为可定义的数据类型,此设为int类型defineMAXSIZE100//顺序表可能达到的最大长度typedefstruct......
  • 2024 ICPC网络赛第一场 CGL (by hzy)
    C.PermutationCounting4(线性代数)大意:求排列计数,限制条件:每个元素位置只能在给定区间\([l,r]\)内,答案模2。行列式最基本的定义是枚举排列,构造一个n阶行列式,让每一行的\([l,r]\)内为1,其余为0,则行列式的值就是答案。考虑模2意义下,01异或行列式为0当且仅当某些行异或起来(初等行......
  • 哔咔漫画最新版2024下载官网版-哔咔漫画2024最新版本永久免费v2.2.1.3-百步下载
    哔咔漫画简介:在当今这个数字化日益发展的时代,二次元文化已经成为许多年轻人的精神食粮之一。哔咔漫画App,作为一款集成了大量正版漫画资源的移动应用,凭借其丰富的内容、优质的用户体验和便捷的操作方式,迅速成为了漫画爱好者们的首选平台。本文将带你深入了解哔咔漫画App的魅力所在......