Java库存管理小案例

库存管理案例

package com.meng.test;

import java.util.Scanner;

public class FunctionDemo06 {
	public static void main(String[] args) {
		String[] names = {"book1","book2"};
		double[] sizes = {12.5,15.6};
		double[] prices = {6009.5,5999.9};
		int[] counts = {0,0};
		boolean flag = true;
		while(flag){
			int choose = Choose();
			switch(choose){
			case 1:
				printStore(names, sizes, prices, counts);
				break;
			case 2:
				update(names, counts);
				break;
			case 3:
				System.out.println("您已退出系统");
				flag=false;
				return;
		}
	}
		 
		
	}
	public static int Choose(){
		System.out.println("----------库存清单----------");
		System.out.println("1.查看库存清单");
		System.out.println("2.修改商品库存数量");
		System.out.println("3.退出");
		System.out.println("请输入要执行的操作序号:");
		int choose = new Scanner(System.in).nextInt();
		return choose;
	}
	
	
	public static void printStore(String[] books, double[] sizes, double[] prices, int[] counts) { 
		//统计总库存个数、统计库存总金额
		int totalCount = 0; 
		double totalMoney = 0.0; 
		for (int i = 0; i < books.length; i++) { 
			totalCount += counts[i]; 
			totalMoney += counts[i] * prices[i]; 
		} 
			 //列表顶部
		System.out.println("--------------------------- 查看库存清单--------------------------"); 
		System.out.println("品牌型号		尺寸	 	价格		库存数"); 
		//列表中部
		for (int i = 0; i < books.length; i++) { 
			System.out.println(books[i]+" 		"+sizes[i]+" 		"+prices[i]+" 		"+counts[i]); 
		} 
			 //列表底部
		System.out.println("-------------------------------------------------------------"); 
		System.out.println("总库存数:"+totalCount); 
		System.out.println("库存商品总金额:"+totalMoney); 
	}
	
	
	public static void update(String[] books, int[] counts){ 
		System.out.println("------------修改商品库存数量-----------"); 
		 for (int i = 0; i < books.length; i++) { 
			 System.out.println("请输入"+ books[i] +"商品库存数"); 
			 counts[i] = new Scanner(System.in).nextInt(); 
		 } 
	}
	

}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值