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.退出");
}
}