zoukankan      html  css  js  c++  java
  • 库存管理案例

    现在,我们将原有的库存管理案例,采用更好的集合方式实现。

     

    将对下列功能进行方法封装:

    l 打印库存清单功能

    l 库存商品数量修改功能

    l 退出程序功能

    1.1 案例需求分析

    管理员能够进行的操作有3项(查看、修改、退出),我们可以采用switch菜单的方式来完成

    -------------库存管理------------

    1.查看库存清单

    2.修改商品库存数量

    3.退出

    请输入要执行的操作序号:

      每一项功能操作,我们采用方法进行封装,这样,可使程序的可读性增强。

    选择“1.查看库存清单功能,则控制台打印库存清单

    选择“2.修改商品库存数量功能,则对每种商品库存数进行更新

    选择“3.退出功能,则退出库存管理,程序结束

    import java.util.Scanner;
    class  store
    {
        public static void main(String[] args) 
        {
            String[] names={"aaa","bbb","ccc"};
            double[] sizes={13.3,14.0,15.6};
            double[] prices={6988.8,6999.0,4999.5};
            int[] counts={5,10,18};
            Scanner sc=new Scanner(System.in);
            while(true){
                show();
                int choose=sc.nextInt();
                switch(choose){
                case 1:showgoods(names,sizes,prices,counts);
                    break;
                case 2:updatecounts(names,sizes,prices,counts);
                    break;
                case 3:
                    return;
                default:
                    System.out.println("您的输入有误,请重新输入");
                }
            }
        }
        public static void show(){
            System.out.println("--------------库存管理-------------");
            System.out.println("1、查看库存清单");
            System.out.println("2、修改商品库存数量");
            System.out.println("3、退出");
            System.out.println("请输入要执行的操作序号:");
        }
        public static void showgoods(String[] names,double[] sizes,double[] prices,int[] counts){
            System.out.println("--------------库存管理-------------");
            System.out.println("品牌型号 尺寸  价格   库存");
                for(int i=0;i<names.length;i++){
                    System.out.println(names[i]+"	"+sizes[i]+"	"+prices[i]+"	"+counts[i]);
                }
        }
        public static void updatecounts(String[] names,double[] sizes,double[] prices,int[] counts){
            showgoods(names,sizes,prices,counts);
            System.out.println("请输入您要修改的商品序号:");
            Scanner sc=new Scanner(System.in);
            int number=sc.nextInt();
            System.out.println("请输入修改后的数量:");
            int count=sc.nextInt();
            counts[number-1]=count;
        }
    }
  • 相关阅读:
    沙盒解决方案与场解决方案之间的差异
    Windows 7:77 个 Windows 7 提示
    SharePoint disable loopback check
    SharePoint 2010 工作流解决方案:序言
    SharePoint 2010 查看“运行时错误”
    sharepoint 链接库链接在新窗口打开
    如何启用SharePoint 2010的代码块
    沙盒解决方案注意事项
    ie8.0 不能用document.all兼容IE7模式
    php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法
  • 原文地址:https://www.cnblogs.com/yang1182/p/9650866.html
Copyright © 2011-2022 走看看