商品信息系统五个小功能

package pre.day04;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class PhoneProductInformation {

	public static void main(String[] args) {
		String[] product= {
				"三星Galaxy","iphoneX","华为P20","小米","vivo","oppo"
		};
		int[] quantity= {88,66,99,100,233,233
		};
		double[] dj= {
				5399.0,8888.0,3999.0,1999.0,2666.0,1999.0
		};
		System.out.println("1.商品列表");
		System.out.println("2.录入商品");
		System.out.println("3.商品查询");
		System.out.println("4.数据统计");
		System.out.println("5.退出程序");
		System.out.println();
		while(true) {
			Scanner scan=new Scanner(System.in);
		
		System.out.println("请输入要选择的功能:");
		int number=scan.nextInt();
		switch(number) {
		case 1:
			for(int i=0;i<product.length;i++) {
				System.out.print("商品"+ (i+1) +" "+product[i]);
				System.out.print(" ");
				for (int j=0;j<quantity.length;j++) {
					if (j==i) {
						System.out.print("数量: "+quantity[j]);
						System.out.print(" ");
						
						for (int s=0;s<dj.length;s++) {
							if(s==j) {
								System.out.print("单价:"+dj[s]);
								System.out.println(" ");
							}
						}
					}
					
				}
			}
			break;
		case 2:
			System.out.println("请输入新增商品的名称:");
			product=Arrays.copyOf(product, product.length +1);
			product[product.length -1]=scan.next();
			System.out.println("请输入商品数量:");
			quantity=Arrays.copyOf(quantity,quantity.length+1);
			quantity[quantity.length-1]=scan.nextInt();
			System.out.println("请输入商品单价");
			dj=Arrays.copyOf(dj,dj.length+1);
			dj[dj.length-1]=scan.nextDouble();
			System.out.println();			
			break;
		case 3:
			System.out.println("请输入您要查询的手机:");
			String check=scan.next();
			for (int i=0;i<product.length;i++) {
				if(check.equals(product[i])) {
					System.out.println("商品:"+product[i]+" 数量: "+quantity[i]+" 单价: "+dj[i]);
									
					break;
			}
			
			}break;
		case 4:
			System.out.println("计算所有商品的单价平均价:");
			double sum=0.0;
			for(int i=0;i<dj.length;i++) {
				sum = sum+dj[i];
				
			}
			System.out.println("单价平均价:"+(sum/dj.length));
			break;
		case 5:
			System.out.println("退出程序");
		 
			return;
			default:
				System.out.println("输入错误");
				
				
				
		}
		}
		

	}

}

猜你喜欢

转载自blog.csdn.net/u011174699/article/details/82820287
今日推荐