package demo;
import java.util.Scanner;
public class textprodtct {
public static void main(String[] args) {
// TODO Auto-generated method stub
Prodect[] prtar = new Prodect[20];
int index = 0;
while (true) {
//模拟商品系统界面
System.out.println("*************************");
System.out.println("********商品管理系统*********");
System.out.println("********1.添加商品*********");
System.out.println("********2.查询商品*********");
System.out.println("********3.修改产品*********");
System.out.println("********4.删除产品*********");
System.out.println("********0.退出系统*********");
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的指令:");
int num = sc.nextInt();
//判断指令
if (num == 1) {
System.out.println("请输入你要添加的商品的名称:");
String name = sc.next();
System.out.println("请输入你要添加的商品的价格:");
int price = sc.nextInt();
System.out.println("请输入你要添加的商品的进货商:");
String factory = sc.next();
System.out.println("请输入你要添加的商品的生产日期:");
int date = sc.nextInt();
//新建一个容器 承装商品
Prodect prodect = new Prodect();
prodect.name = name;
prtar[index] = (Prodect) prodect;
index++;
System.out.println("商品添加成功!");
}
//查询商品
else if (num == 2) {
for (int i = 0; i < index; i++) {
System.out.println("名称"+prtar[i].name+"价格"+prtar[i].price);
}
}
//修改产品
else if (num == 3) {
System.out.println("请输入要修改的商品的名称:");
String moname = sc.next();
int monameindex = -1;
//定位下标
for (int i = 0; i < index; i++) {
if (prtar[i].name.equals(moname)) {
monameindex = i;
}
}
if (monameindex == -1) {
System.out.println("该商品不存在!");
}
else {
System.out.println("请输入你要修改的新名称:");
String name = sc.next();
System.out.println("请输入价格:");
int price = sc.nextInt();
System.out.println("请输入生产日期:");
int date = sc.nextInt();
//构建一个容器
Prodect prodect = new Prodect();
prodect.price = price;
prodect.date = date;
prtar[monameindex] = prodect;
System.out.println("商品修改成功!");
}
}
}
}
public static class Prodect {
String name;
int num;
String factory;
int date;
int price;
}
}