JAVA基础练习_商品库存案例

import java.util.Scanner;
public class PracticeDemo_3{
    /*
      实现一个简单的商品库存案例
      需求分析:1.定义数组,存储商品信息;
                2.预览数组,预览商品;
                3.用户可修改商品*/
    public static void main(String[] args){
        //1.定义商品名称,数量,价格
        String [] brand ={"联想","华硕","戴尔"};
        int [] count ={2,2,1};
        double [] price ={4299.9,3888.8,5999.9};
        
        boolean flag =true;
        while(flag){
        //2.用户选择功能
        System.out.println("----------------商品库存案例------------");
        System.out.println("请选择需要的功能:"+"\n"+"1.查看商品信息"+"\n"+"2.修改商品库存数量"+"\n"+"3.退出"+"\n"+"请选择功能序号:");
        Scanner sc =new Scanner(System.in);
        int number =sc.nextInt();
        switch (number){
            case 1:
                seeStore(brand,count,price);
                break;
            case 2:
                updateCount(brand,count);
                break;
            case 3:
                System.out.println("系统已退出");
                flag = false;
        }
        }
    }
    /*
    定义一个方法,查看商品信息
    */
    public static void seeStore(String[] brand,int[] count,double[] price){
        int totalPrice =0;
        int totalCount =0;
        System.out.println("商品名称    商品数量    价格");
        for(int i=0;i<brand.length;i++){
            System.out.println(brand[i]+"           "+count[i]+"           "+price[i]);
             totalPrice += count[i] * price[i];
             totalCount += count[i];
        }
        System.out.println("商品库存总数量为:"+totalCount);
        System.out.println("商品库存总价格为:"+totalPrice);
    }
    /*
    定义一个方法,修改商品数量
    */
    public static void updateCount(String[] brand,int[] count){
        for(int i=0; i<brand.length;i++){
            System.out.println("商品名称:"+"  "+brand[i]);
            System.out.println("修改数量为:");
            Scanner sc=new Scanner(System.in);
            int number =sc.nextInt();
            count[i]=number;
        }
    }
}
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值