• 最简单的库存管理java案例


    package com.tedu.day05;
    
    import java.util.Scanner;
    
    public class Demo {
    
        /**
         * 管理员能够进行的操作有3项(查看、修改、退出),我们可以采用(switch)菜单的方式来完成。
         *  -------------库存管理------------
         *         1.查看库存清单
         *         2.修改商品库存数量 
         *         3.退出 请输入要执行的操作序号: 
         *             每一项功能操作,我们采用方法进行封装,这样,可使程序的可读性增强。
         *         选择“1.查看库存清单”功能,则控制台打印库存清单 
         *         选择“2.修改商品库存数量”功能,则对每种商品库存数进行更新
         *         选择“3.退出”功能,则退出库存管理,程序结束
         */
        public static void main(String[] args) {
            String[] brand = {"MacBook","ThinkPad"};
            double[] size = {13.3,14.7};
            double[] price = {7988.88,6999.88};
            int[] count = {0,0};
            
            while(true){
            printMenu();
            System.out.println("请输入菜单选项:");
            Scanner scan =new Scanner(System.in);
            int number = scan.nextInt();
            switch(number){
                case 1:
                    printStock(brand, size, price, count);
                    break;
                case 2:
                    alterCount(brand, count);
                    break;
                case 3:
                    System.out.println("欢迎下次再来!!!");
                    return;
                default:
                        System.out.println("输入格式或字符错误,请重新输入");
                        
            }
                
            }
        }
        
        //数组遍历查看库存的方法
        public static void printStock(String[] brand, double[] size, double[] price,int[] count){
            int totalCount = 0;
            double totalPrice = 0;
            System.out.println("--------库存管理--------");
            System.out.println("品名----------尺寸----------价格----------数量");
            for(int i=0;i<brand.length;i++){
                System.out.println(brand[i]+"------"+size[i]+"---------"+price[i]+"------"+count[i]+"	");
                totalCount += count[i];
                totalPrice = count[i]*price[i];
            }
            System.out.println("----------------------------");
            System.out.println("库存总量:"+totalCount);
            System.out.println("库存总金额:"+totalPrice);
        }
        
        //修改商品库存的方法
        public static void alterCount(String[] brand,int[] count){
            
            for(int i=0;i<count.length;i++){
                System.out.println("请输入"+brand[i]+"的数量");
                Scanner scan = new Scanner(System.in);
                int newCount = scan.nextInt();
                count[i] = newCount;
            }
            
        }
        
        //显示功能菜单的方法
        public static void printMenu(){
            System.out.println("1.查看库存清单");
            System.out.println("2.修改库存数量");
            System.out.println("3.退出");
        }
    }

    功能还能拓展。。。

  • 相关阅读:
    node 跨域请求设置
    iOS下如何阻止橡皮筋效果
    您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决
    您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决
    ImageButton的坑 ImageButton 有问题
    ImageButton的坑 ImageButton 有问题
    ImageButton的坑 ImageButton 有问题
    textView代码设置文字居中失效 textView设置文字居中两种方法
    textView代码设置文字居中失效 textView设置文字居中两种方法
    textView代码设置文字居中失效 textView设置文字居中两种方法
  • 原文地址:https://www.cnblogs.com/msn-z/p/6953462.html
Copyright © 2020-2023  润新知