制作一个简单的商品销售系统
import java.util.Scanner;
class Pro {
static String[] name = new String[6];//名称
static int[] number = new int[6];//序号
static int[] price = new int[6];//价格
static int[] sum = new int[6];//数量
public static void ProductInformation() {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 6; i++) {
number[i] = sc.nextInt();
name[i] = sc.next();
price[i] = sc.nextInt();
sum[i] = sc.nextInt();
}
}
public static void compute() {
int averge=0;
int number2=0;
int totalValue=0;
for(int i=0;i<6;i++){
averge+=price[i];
number2+=sum[i];
totalValue+=price[i]*sum[i];
}
}
public static void sort() {
int price1[] = new int[6];
for (int i = 0; i < 6; i++) {
price1[i] = price[i];
}
for (int j = 0; j < 6 - 1; j++) {
for (int i = 0; i < 6 - j - 1; i++) {
if (price1[i] > price1[i + 1]) {
int x = price1[i + 1];
price1[i + 1] = price1[i];
price1[i] = x;
}
}
}
for (int i = 0; i < 6; i++) {
for(int j=0;j<6;j++){
if (price[j]==price1[i])
{
System.out.println(number[j]);
break;
}
}
}
}
}
public class Product {
public static void main(String[] args) {
while (true){//无限循环
System.out.println("欢迎进入商品销售系统!");
System.out.println("0:首先输入6种商品信息");//序号 名称 价格 数量。
System.out.println("本次查询的功能有以下 ");
System.out.println("1:计算所有商品价格平均值,商品总数量,总价值");
System.out.println("2:为商品进行价格排序");
System.out.println("3:退出系统");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
switch (x) {
case 0:
Pro.ProductInformation();
break;
case 1:
Pro.compute();
break;
case 2:
Pro.sort();
break;
case 3:
System.out.println("本次查询结束,欢迎下次查询");
break;
}
}
}
}