/*
实现商品的库存管理
功能:
1. 展示用户选择功能清单
2. 根据选择的功能编号,进行不同的操作
A. 展示所有库存
B. 修改库存数量
分析:
1. 展示用户清单:
输出语句, 用户输入, 选择功能序号
2. 根据选择,调用不同的方法
switch语句
case 1 2 3
A 展示库存
将存储商品的数组,遍历
B 修改库存
修改所有的库存数量
*/
import java.util.Scanner;
public class StoreOperation{
public static void main(String[] args){
//使用数组,保存商品的信息
//品名,尺寸,价格,库存数, 定义5个数组
String[] brand = {"MacBookAir","ThinkpadT6"};
double[] size = {13.3,15.6};
double[] price = {9998.97,6789.56};
int[] count = {0,0};
//接收用户选择的功能
while(true){
int cf = chooseFunction();
switch(cf){
case 1 :
//调用查看用户清单的方法
printStore(brand,size,price,count);
break;
case 2:
//调用修改库存数量的方法
update(brand,count);
break;
case 3:
return ;
default:
System.out.println("没有这个功能");
break;
}
}
}
/*
定义方法,展示所有的库存清单,遍历
返回值,没有
参数, 数组
*/
public static void printStore(String[] brand,double[] size,double[] price,int[] count){
System.out.println("----------商场库存清单----------");
System.out.println("品牌型号 尺寸 价格 库存数");
//定义变量,计算总库存数,和总价格
int totalCount = 0;
double totalMoney = 0;
//便利数组,把所有的数据输出
for(int i = 0 ; i < brand.length ; i++){
System.out.println(brand[i]+" "+size[i]+" "+price[i]+" "+count[i]);
totalCount += count[i];
totalMoney += count[i]*price[i];
}
System.out.println("---------------------------------");
System.out.println("总库存数: "+totalCount);
System.out.println("商品库存总金额: "+totalMoney);
System.out.println();
System.out.println();
}
/*
定义方法,实现用户的选择功能,功能的需要返回来
返回值, int
参数, 没有
*/
public static int chooseFunction(){
System.out.println("-------------库存管理------------");
System.out.println("1.查看库存清单");
System.out.println("2.修改商品库存数量");
System.out.println("3.退出");
System.out.print("请输入要执行的操作序号:");
//接受键盘输入
Scanner sc = new Scanner(System.in);
int chooseNumber = sc.nextInt();
return chooseNumber;
}
/*
定义方法,修改所有商品的库存
用户输入1个,修改1个
返回值,没有
参数, 库存数的数组, 品名数组
*/
public static void update(String[] brand,int[] count){
Scanner sc = new Scanner(System.in);
for(int i = 0 ; i < brand.length ; i++){
System.out.println("请输入"+brand[i]+"的库存数量:");
int newCount = sc.nextInt();
count[i] = newCount;
}
}
}
简单实现商品库存修改,统计全部库存数量和计算所有库存货物的总金额
猜你喜欢
转载自blog.csdn.net/qq_38054319/article/details/86356047
今日推荐
周排行