import java.util.Scanner;
import java.util.Arrays;
class gwc2{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
//用java se(两个数组)制作一个gwc
String[] sp={"1-车厘子","2-花生"};//商品
int[] gwcxh=new int[0];//购物车内商品序号
for(;;){
System.out.println("············");
System.out.println("欢迎光临笛笛购物车");
System.out.println("可供选择的操作有:");
System.out.println("1、查看购物车商品;");
System.out.println("2、增加购物车商品;");
System.out.println("3、减少购物车商品;");
System.out.println("0、退出;");
int xh=sc.nextInt();
if(1==xh){
System.out.println("购物车里面的商品有:");
for(int i=0;i
System.out.print(sp[gwcxh[i]]+" ");
}
}else if(2==xh){
System.out.println("可供您添加的商品有:");
for(int i=0;i
System.out.print(sp[i]+" ");
}
System.out.println();
System.out.println("请选择您想添加商品的序号");
int a=sc.nextInt()-1;
gwcxh=Arrays.copyOf(gwcxh,gwcxh.length+1);
gwcxh[gwcxh.length-1]=a;
System.out.println("添加成功");
}else if(3==xh){
System.out.println("购物车里面的商品有:");
for(int i=0;i
System.out.print(sp[gwcxh[i]]+" ");
}
System.out.println("请选择您想删除第几个商品");
int a=sc.nextInt()-1;
for(int i=a;i
gwcxh[i]=gwcxh[i+1];
if(i==gwcxh.length-2){//当他是倒数第二个商品时:
gwcxh=Arrays.copyOf(gwcxh,gwcxh.length-1);
}
}
System.out.println("删除成功");
}else if(0==xh){
//退出JAVA虚拟机;后面参数是状态码;0是正常退出,非0是不正常退出
System.exit(0);
}else{
System.out.println("请输入正确操作序号");
}
}
}
}



