首页 > 其他分享 >开学考试

开学考试

时间:2023-09-16 22:13:04浏览次数:42  
标签:开学 String int System println public 考试 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;
    }
}

 

标签:开学,String,int,System,println,public,考试,out
From: https://www.cnblogs.com/Mini-Q/p/17707398.html

相关文章

  • 考试代码
    package拉倒吧;importjava.util.Scanner;publicclassWarehouseInformation{ Stringitemno;//编号 Stringitemname;//商品名称 Stringsuppliername;//供货商名称 Stringwarehousingtime;//入库时间 Stringshipmenttime;//出库时间 Stringwarehousenumber;//仓库编号 St......
  • 开学测试整理
    WarehouseInformation系统的增删改查操作一、实现WarehouseInformation类中的成员变量,赋值函数等;代码如下:publicclassWarehouseInformation{privateStringitemno;//表示商品编号(有8位数字组成)privateStringitemname;//表示商品名称privateStringsup......
  • 基于java的在线考试系统的设计-计算机毕业设计源码+LW文档
    摘要随着信息技术的发展,管理系统越来越成熟,各种企事业单位使用各种类型的管理系统来提高工作效率,从而降低手工操作的弊端。我国政府一直以来都非常重视高校教育的发展,近几年来高校学生人数逐渐增加,对在线考试的需求越来越多。因此,通过开发基于java的在线考试系统来提高学习效率,增......
  • 仓库管理系统————开学测试(重写)
    WarehouseInformation类packageSTD_STD;publicclassWarehouseInformation{privateStringitemnumber;privateStringitemname;privateStringsuppliername;privateStringwarehousingtime;privateStringshipmenttime;privateStrin......
  • 2023秋Java开学考试代码优化
    publicclassWarehouseInformation{privateStringitemno;privateStringitemname;privateStringsuppliername;privateStringwarehousingtime;privateStringwarehousenumber;privateStringshipmenttime;privateStringwareho......
  • 软工开学考试
    一、题目一、考试要求:1、按照测试内容要求完成程序的设计与编程;2、建立学号姓名文件夹,如:“信2205-1班20223921赵福奇”,将源程序文件、保存在文件夹中,压缩成rar文件提交。3、以班级为单位上交最终考试结果。4、需要在程序开始的注释中注明班级、学号、姓名。二、系统背景:某......
  • 信竞考试策略总结
    一、对于平常的CSP/NOIP/模拟考1.考试策略首先,通读题面,作出开题的选择。做好部分分的思考,建议将所有的简单的部分分都完全思考清楚再去开签到题。写完一道题的代码/思考好一道题之后,可以去厕所整理一下思路,进行放松。一张一弛才能有更好的发挥最后仅剩\(1.5h\)时,果断放......
  • Java学习_006_考试奖励
    需求:小明期末考试,小明的爸爸对他说,会根据他不同的期末考试成绩,送他不同的礼物,假如你可以控制小明的得分,请用程序实现小明到底该获得什么样的礼物,并在控制台输出。     奖励:95-100-----山地自行车一辆;  90-94------游乐场游玩一次;80-89----......
  • 备考11月份PMP考试还来得及吗?
    2023年共有4次PMP®考试,分别是3月、5月、8月、11月,现在仅剩11月还有一次考试,也是今年可参加的最后一次PMP®考试。那么,现在备考11月份PMP®考试还来得及吗? 答案是肯定的。现在开始备考11月PMP®考试,时间是很充裕的。  如果你有一定的经验基础,那么备考一个半月左右的时间就没有问......
  • Codeforces Round 897 (Div. 2) 考试总结
    前言这次打得很好,相较于div3的脑残题和签到题来说,div2的思维难度更加的大。同时还有除传统题外,其他的题型出现。比如交互题等。这次能在考场上想出三道较于之前是有很大的进步的。赛时实况:ABCDE1E2F√√√××××赛后改题情况:ABCDE1E2F......