1 import java.util.Scanner; 2 3 public class TestOne { 4 public static void main(String[] args) { 5 //定义5个数组 6 String [] brand = {"MacBookAir","ThinkPadT450"}; 7 double [] size = {13.3,15.6}; 8 double [] price = {9999.99,6666.66}; 9 int [] count = {0,0}; 10 while(true) { 11 int choose = chooseFunction(); 12 switch (choose) { 13 case 1: 14 show(brand, size, price, count); 15 break; 16 case 2: 17 change(brand, count); 18 break; 19 case 3: 20 return; 21 default: 22 System.out.println("输入有误没有这个功能"); 23 break; 24 } 25 } 26 27 } 28 //实现用户的选择功能,把功能的需要返回 29 public static int chooseFunction() { 30 System.out.println(">>>>>>欢迎登陆库存管理系统6.b"); 31 System.out.println("1.查看商品库存清单"); 32 System.out.println("2.修改商品库存数量"); 33 System.out.println("3.退出"); 34 System.out.println("请输入要执行的操作序号:"); 35 //接受用户键盘输入 36 Scanner sc = new Scanner(System.in); 37 int chooseNumber = sc.nextInt(); 38 return chooseNumber; 39 } 40 //展示所有库存清单 41 public static void show(String[] brand,double [] size,double [] price,int [] count) { 42 System.out.println("---------商品库存清单---------"); 43 System.out.println("品牌型号 尺寸 价格 库存数"); 44 //定义变量,计算总库存,和总价格 45 int totalCount = 0; 46 int totalMoney = 0; 47 for(int i = 0;i<brand.length;i++) { 48 System.out.println(brand[i]+" "+size[i]+" "+price[i]+" "+count[i]); 49 totalCount += count[i]; 50 totalMoney += count[i]*price[i]; 51 } 52 System.out.println("总库存数:" + totalCount); 53 System.out.println("商品总金额:" + totalMoney); 54 } 55 //修改所有商品的库存数量 56 public static void change(String[] brand,int [] count) { 57 System.out.println(""); 58 Scanner sc = new Scanner(System.in); 59 for(int i = 0;i<brand.length;i++) { 60 System.out.println("请输入"+brand[i]+"库存数"); 61 int userCount = sc.nextInt(); 62 count[i] = userCount; 63 } 64 } 65 }