package nn;
import java.util.Scanner;
public class ShopDemo {
/* 主函数中 定义三个数组:商品,价格,库存量
* 利用while循环,从用户界面输入选择要查看的功能
* while循环中利用switch语句提供用户选择查看功能
* */
public static void main(String[] args) {
String[] shop = {"airbo","hasee"};
double[] price = {9999.5,4444};
int[] count = {0,0};
while(true){
int choose = chooeseShop();
switch(choose){
case 1:
printshop(shop,price,count);
break;
case 2:
updata(shop,count);
break;
case 3:
return;
default:
System.out.println("没有这个功能!");
}
}
}
/*建立一个方法显示商品名
* 遍历输出商品
* 和计算库存总数和总价格*/
public static void printshop(String[] shop,double[] price,int[] count){
System.out.println("=============商品列表===============");
System.out.println("商品名称 商品价格 商品个数");
int countsum = 0;
double countprice = 0;
for(int i=0;i<shop.length;i++){
System.out.println(shop[i]+" "+price[i]+" "+count[i]); //遍历输出商品,价格,库存总数
countsum += count[i]; //计算价格
countprice += count[i] * price[i];
}
System.out.println("商品库存的总量:"+countsum + " 台");
System.out.println("商品库存的总价格:"+countprice + " 元");
}
/*建立方法对商品的库存进行更新操作
* 利用Scanner函数从用户手中输入库存数量
*
* */
public static void updata(String[] shop,int[] count){
Scanner sca = new Scanner(System.in);
for(int i = 0;i<shop.length;i++){
System.out.println("请输入" + shop[i] + "数量");
int s = sca.nextInt(); //利用nextInt();输入库存数;
count[i] = s; //吧输入的库存数传递到数组中的count中,实现修改库存
}
}
/*建立一个现实用户要选择的更能界面*/
public static int chooeseShop(){
System.out.println("=====请选择您要进行的查询:===========-=");
System.out.println(" 1.展示商品的列表:");
System.out.println(" 2.修改商品库存:");
System.out.println(" 3.退出");
Scanner sca = new Scanner(System.in);
return sca.nextInt();
}
}
import java.util.Scanner;
public class ShopDemo {
/* 主函数中 定义三个数组:商品,价格,库存量
* 利用while循环,从用户界面输入选择要查看的功能
* while循环中利用switch语句提供用户选择查看功能
* */
public static void main(String[] args) {
String[] shop = {"airbo","hasee"};
double[] price = {9999.5,4444};
int[] count = {0,0};
while(true){
int choose = chooeseShop();
switch(choose){
case 1:
printshop(shop,price,count);
break;
case 2:
updata(shop,count);
break;
case 3:
return;
default:
System.out.println("没有这个功能!");
}
}
}
/*建立一个方法显示商品名
* 遍历输出商品
* 和计算库存总数和总价格*/
public static void printshop(String[] shop,double[] price,int[] count){
System.out.println("=============商品列表===============");
System.out.println("商品名称 商品价格 商品个数");
int countsum = 0;
double countprice = 0;
for(int i=0;i<shop.length;i++){
System.out.println(shop[i]+" "+price[i]+" "+count[i]); //遍历输出商品,价格,库存总数
countsum += count[i]; //计算价格
countprice += count[i] * price[i];
}
System.out.println("商品库存的总量:"+countsum + " 台");
System.out.println("商品库存的总价格:"+countprice + " 元");
}
/*建立方法对商品的库存进行更新操作
* 利用Scanner函数从用户手中输入库存数量
*
* */
public static void updata(String[] shop,int[] count){
Scanner sca = new Scanner(System.in);
for(int i = 0;i<shop.length;i++){
System.out.println("请输入" + shop[i] + "数量");
int s = sca.nextInt(); //利用nextInt();输入库存数;
count[i] = s; //吧输入的库存数传递到数组中的count中,实现修改库存
}
}
/*建立一个现实用户要选择的更能界面*/
public static int chooeseShop(){
System.out.println("=====请选择您要进行的查询:===========-=");
System.out.println(" 1.展示商品的列表:");
System.out.println(" 2.修改商品库存:");
System.out.println(" 3.退出");
Scanner sca = new Scanner(System.in);
return sca.nextInt();
}
}