首页 > 其他分享 >源代码

源代码

时间:2023-09-17 12:33:41浏览次数:28  
标签:scanner String int System println 源代码 out

源代码:

import java.util.Scanner;


// 数据类 WarehouseInformation
class WarehouseInformation {
    private String productId;
    private String productName;
    private String supplier;
    private String entryDate;
    private int warehouseNumber;
    private String location;
    private int stockQuantity;

    public WarehouseInformation(String productId, String productName, String supplier, String entryDate, int warehouseNumber, String location, int stockQuantity) {
        this.productId = productId;
        this.productName = productName;
        this.supplier = supplier;
        this.entryDate = entryDate;
        this.warehouseNumber = warehouseNumber;
        this.location = location;
        this.stockQuantity = stockQuantity;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public void setSupplier(String supplier) {
        this.supplier = supplier;
    }

    public void setEntryDate(String entryDate) {
        this.entryDate = entryDate;
    }

    public void setWarehouseNumber(int warehouseNumber) {
        this.warehouseNumber = warehouseNumber;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public void setStockQuantity(int stockQuantity) {
        this.stockQuantity = stockQuantity;
    }
    public String getProductId() {
        return productId;
    }

    public String getProductName() {
        return productName;
    }

    public String getSupplier() {
        return supplier;
    }

    public String getEntryDate() {
        return entryDate;
    }

    public int getWarehouseNumber() {
        return warehouseNumber;
    }

    public String getLocation() {
        return location;
    }

    public int getStockQuantity() {
        return stockQuantity;
    }
}

// 主类 WarehouseManagement
public class WarehouseManagement {
    private static WarehouseInformation[] warehouse; // 仓库信息数组
    private static int warehouseCount = 0;

    public static void main(String[] args) {
        // 初始化仓库数组
        warehouse = new WarehouseInformation[100];

        // 在这里调用主界面方法
        mainFrame();
    }

    public static void mainFrame() {
        // 绘制主界面,获取用户输入,判断选择功能界面
        Scanner scanner = new Scanner(System.in);
        int choice;

        do {
            System.out.println("请选择功能:");
            System.out.println("1. 商品入库");
            System.out.println("2. 商品修改");
            System.out.println("3. 商品出库");
            System.out.println("4. 统计商品库存数量");
            System.out.println("0. 退出");
            choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    goodsWarehousing();
                    break;
                case 2:
                    modifyWarehouse();
                    break;
                case 3:
                    outboundWarehouse();
                    break;
                case 4:
                    countGoods();
                    break;
                case 0:
                    System.out.println("退出程序");
                    break;
                default:
                    System.out.println("请选择有效的功能!");
                    break;
            }
        } while (choice != 0);
    }

    public static void goodsWarehousing() {
        // 商品入库方法的实现
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入商品编号:");
        String productId = scanner.next();

        // 检查商品是否已存在
        int existingIndex = findWarehouseIndex(productId);
        if (existingIndex != -1) {
            System.out.println("商品已存在,无法入库。");
            return;
        }

        System.out.println("请输入商品名称:");
        String productName = scanner.next();

        System.out.println("请输入供货商信息:");
        String supplier = scanner.next();

        System.out.println("请输入入库时间:");
        String entryDate = scanner.next();

        System.out.println("请输入存放仓库号:");
        int warehouseNumber = scanner.nextInt();

        System.out.println("请输入存放位置信息:");
        String location = scanner.next();

        System.out.println("请输入入库数量:");
        int stockQuantity = scanner.nextInt();

        if (stockQuantity <= 0) {
            System.out.println("入库数量必须大于0。");
            return;
        }

        System.out.println("是否确认入库(Y/N):");
        String confirmation = scanner.next();

        if (confirmation.equalsIgnoreCase("Y")) {
            // 调用addData()方法追加一条新记录
            WarehouseInformation newWarehouse = new WarehouseInformation(productId, productName, supplier, entryDate, warehouseNumber, location, stockQuantity);
            addData(newWarehouse);
            System.out.println("商品入库成功!");
        }
    }

    public static void modifyWarehouse() {
        // 商品修改方法的实现
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入要修改的商品编号:");
        String productId = scanner.next();

        int index = findWarehouseIndex(productId);

        if (index == -1) {
            System.out.println("商品不存在,无法修改。");
            return;
        }

        WarehouseInformation warehouseInfo = warehouse[index];

        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("6. 入库数量");
        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                System.out.println("请输入新的商品名称:");
                String newProductName = scanner.next();
                warehouseInfo.setProductName(newProductName);
                break;
            case 2:
                System.out.println("请输入新的供货商信息:");
                String newSupplier = scanner.next();
                warehouseInfo.setSupplier(newSupplier);
                break;
            case 3:
                System.out.println("请输入新的入库时间:");
                String newEntryDate = scanner.next();
                warehouseInfo.setEntryDate(newEntryDate);
                break;
            case 4:
                System.out.println("请输入新的存放仓库号:");
                int newWarehouseNumber = scanner.nextInt();
                warehouseInfo.setWarehouseNumber(newWarehouseNumber);
                break;
            case 5:
                System.out.println("请输入新的存放位置信息:");
                String newLocation = scanner.next();
                warehouseInfo.setLocation(newLocation);
                break;
            case 6:
                System.out.println("请输入新的入库数量:");
                int newStockQuantity = scanner.nextInt();
                warehouseInfo.setStockQuantity(newStockQuantity);
                break;
            default:
                System.out.println("请选择有效的信息编号。");
                break;
        }

        System.out.println("商品信息修改成功!");
    }

    public static void outboundWarehouse() {
        // 商品出库方法的实现
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入要出库的商品编号:");
        String productId = scanner.next();

        int index = findWarehouseIndex(productId);

        if (index == -1) {
            System.out.println("商品不存在,无法出库。");
            return;
        }

        WarehouseInformation warehouseInfo = warehouse[index];

        int stockQuantity = warehouseInfo.getStockQuantity();

        System.out.println("商品库存数量为:" + stockQuantity);

        System.out.println("请输入出库数量:");
        int quantityToOutbound = scanner.nextInt();

        if (quantityToOutbound <= 0 || quantityToOutbound > stockQuantity) {
            System.out.println("出库数量无效,无法出库。");
            return;
        }

        warehouseInfo.setStockQuantity(stockQuantity - quantityToOutbound);
        System.out.println("商品出库成功!");
    }

    public static void countGoods() {
        // 统计商品库存数量方法的实现
        for (int i = 0; i < warehouseCount; i++) {
            WarehouseInformation warehouseInfo = warehouse[i];
            String productId = warehouseInfo.getProductId();
            String productName = warehouseInfo.getProductName();
            int stockQuantity = warehouseInfo.getStockQuantity();

            System.out.println("商品编号:" + productId);
            System.out.println("商品名称:" + productName);
            System.out.println("库存数量:" + stockQuantity);
            System.out.println();
        }
    }

    public static void addData(WarehouseInformation newWarehouse) {
        if (warehouseCount < warehouse.length) {
            warehouse[warehouseCount++] = newWarehouse;
        } else {
            System.out.println("仓库已满,无法继续入库。");
        }
    }

    public static int findWarehouseIndex(String productId) {
        for (int i = 0; i < warehouseCount; i++) {
            if (warehouse[i].getProductId().equals(productId)) {
                return i;
            }
        }
        return -1;
    }
}

 

标签:scanner,String,int,System,println,源代码,out
From: https://www.cnblogs.com/Hugo-Martin/p/17708209.html

相关文章

  • 程序员 AI 助手来了,蚂蚁正式开源代码大模型 CodeFuse
    9月8日,外滩大会分论坛上,蚂蚁集团首次开源了代码大模型CodeFuse。支付宝小程序云负责人李铮宣布CodeFuse正式开源这是蚂蚁自研的代码生成专属大模型,根据开发者的输入提供智能建议和实时支持,帮助开发者自动生成代码、自动增加注释,自动生成测试用例,修复和优化代码等,以提升研发......
  • 从源代码安装UE5.2
    总体上按照UE5在文档上源码编译流程进行安装,这里只说几个遇到的问题。出现MSB错误:查看log是否出现过warning,MSB错误可能是由于之前的其他问题导致的。在无其他问题的状况下,考虑是否是中文路径,或者路径长度突破了windows中260字符的限制。启动UE5.2后无法新建项目,输出错误为???......
  • nopi 2.6.1 读word docx,写Excel xsls 源代码例子
    ///<summary>///获取.docx文件内容,使用NPOI.XWPF插件解析///</summary>///<paramname="strFilePath">文件路径</param>///<returns></returns>publicstringGetDocxContent(stri......
  • dotnet 使用增量源代码生成技术的 Telescope 库导出程序集类型
    本文将告诉大家在dotnet里面使用免费完全开源的基于增量源代码生成技术的Telescope库,进行收集导出项目程序集里面指定类型。可以实现性能极高的指定类型收集,方便多模块对接入自己的业务框架此Telescope库是基于最友好的MIT协议开源的,免费开源可商用:https://github.com/do......
  • 百度开源网关BFE源代码阅读
    BFE是一个非常强大的七层负载均衡,与其他负载均衡存在一些显著的差异(Product,GSLB等概念),也因为这些差异所以对于没有阅读其代码的用户在入门阶段非常的不友好,再者就是官方文档仅是一个查阅文档,这个查阅文档会的看得懂,不会的看不懂,对于教会用户怎么用实在是没有太多的帮助,所以笔......
  • java 支持 超大上G,多附件上传源代码
    ​ javaweb上传文件上传文件的jsp中的部分上传文件同样可以使用form表单向后端发请求,也可以使用ajax向后端发请求    1.通过form表单向后端发送请求         <formid="postForm"action="${pageContext.request.contextPath}/UploadServlet"method="post"e......
  • dotnet 读 WPF 源代码笔记 渲染层是如何将字符 GlyphRun 画出来的
    从业务代码构建出来GlyphRun对象,在WPF的渲染层里,如何利用GlyphRun提供的数据将字符在界面呈现出来。本文将和大家聊聊从WPF的渲染层获取到GlyphRun数据,到调用DirectX的各个渲染相关方法的过程,也就是WPF绘制文本字符的原理或者实现方法大家印象中的绘制一段文本是调......
  • dotnet 读 WPF 源代码笔记 聊聊 HwndWrapper
    我在阅读WPF源代码,在HwndWrapper的静态构造函数看到了申请了HwndWrapper.GetGCMemMessage这个Windows消息,好奇这个消息是什么功能的。通过阅读WPF源代码和写测试应用,了解到这是一个完全用来内部测试或调试的消息,没有任何业务上的功能在WPF的HwndWrapper的静态构造......
  • dotnet 读 WPF 源代码笔记 GlyphRun 的 DeviceFontName 的功能是什么
    在WPF里面的GlyphRun里,有一个令人迷惑的DeviceFontName属性,似乎给这个属性传入什么值,结果都不会有变更。通过阅读源代码,可以了解到,这是一个没什么用途的属性。本文将告诉大家这个属性的细节逻辑在上一篇博客WPF简单聊聊如何使用DrawGlyphRun绘制文本里面就提到如何创......
  • 如何利用FuncGPT告别繁琐的开源代码调试
    作为一名开发人员,您是否曾经在浩如烟海的开源社区中搜索代码,然后花费大量时间测试、调试,最后才发现这些代码并不符合您的需求?专注Java生成AI函数的FuncGPT(慧函数)就像您的私人编程助手,只需输入你的需求,就能提供符合要求的函数,让你告别繁琐的搜索、测试和调试,迈向高效的开发之旅。一......