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

packagecom.tedu.day05;importjava.util.Scanner;public classDemo {/*** 管理员能够进行的操作有3项(查看、修改、退出),我们可以采用(switch)菜单的方式来完成。

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

* 1.查看库存清单

* 2.修改商品库存数量

* 3.退出 请输入要执行的操作序号:

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

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

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

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

public static voidmain(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=newScanner(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

System.out.println(brand[i]+"------"+size[i]+"---------"+price[i]+"------"+count[i]+"\t");

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

System.out.println("请输入"+brand[i]+"的数量");

Scanner scan= newScanner(System.in);int newCount =scan.nextInt();

count[i]=newCount;

}

}//显示功能菜单的方法

public static voidprintMenu(){

System.out.println("1.查看库存清单");

System.out.println("2.修改库存数量");

System.out.println("3.退出");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值