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;
}
}
}
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;
}
}
}