package 超市管理系统;
public class Manifest {
public Manifest() {
super();
// TODO 自动生成的构造函数存根
}//定义一个货物清单
private String name;
private double price;
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Manifest(int id, double price, String name) {
super();
this.id = id;
this.price = price;
this.name = name;
}
@Override
public String toString() {
return id+"\t"+price+"\t"+name;
}
}
package 超市管理系统;
import java.util.*;
public class Supermarket {
//定义一个超市管理系统
public static void main(String[] args) {
Manifest[] m=new Manifest[1];//定义一个Manifest数组,容量为3
m[0]=new Manifest(3001,3.5,"西红柿");
Scanner sc=new Scanner(System.in);
System.out.println("==================丁某人的超市管理系统==================");
System.out.println("1.货物清单 2.增加货物 3.修改货物 4.删除货物 5.退出");
while(true) {
System.out.println("请输入你要操作的的编号:");
int s=sc.nextInt();
if(s==1) {
try {
System.out.print("正在进入货物清单入口");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
System.out.println("");
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("");
System.out.println("编号\t价格\t商品\t");
for(int i=0;i<m.length;i++) {
System.out.println(m[i]);
}
}
if(s==2) {
System.out.print("正在进入增加货物入口");
try {
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
System.out.println("");
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
m=Arrays.copyOf(m,m.length+1);
for(int i=0;i<m.length;i++) {
m[m.length-1]=new Manifest();
System.out.println("请输入新商品的编号:");
int s1=sc.nextInt();
if(s1==m[i].getId()) {
System.out.println("添加失败,商品编号冲突");
break;
}else {
m[m.length-1].setId(s1);
System.out.println("请输入新商品的价格:");
double s2=sc.nextDouble();
m[m.length-1].setPrice(s2);
System.out.println("请输入商品的名字:");
String s3=sc.next();
if(s3.equals(m[i])) {
System.out.println("添加失败,商品名字冲突");
break;
}else {
m[m.length-1].setName(s3);
m[m.length-1]=new Manifest(s1,s2,s3);
System.out.println("添加成功");
break;
}
}
}
}
if(s==3) {
System.out.print("正在进入修改货物入口");
try {
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
System.out.println("");
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("请输入要修改的编号");
int s1=sc.nextInt();
for(int i=0;i<m.length;i++) {
if(s1==m[i].getId()) {
System.out.println("请输入修改后的编号:");
int s11=sc.nextInt();
if(s11==m[i].getId()) {
System.out.println("修改失败,新编号不能与旧编号相同");
break;
}else {
m[m.length-1].setId(s11);
System.out.println("请输入新的修改后的价格:");
double s2=sc.nextDouble();
m[m.length-1].setPrice(s2);
System.out.println("请输入修改后的商品名字:");
String s3=sc.next();
if(s3.equals(m[i].getName())) {
System.out.println("修改失败,商品名不能喝旧商品名相同");
break;
}else {
m[m.length-1].setName(s3);
m[m.length-1]=new Manifest(s1,s2,s3);
System.out.println("修改成功");
break;
}
}
}
}
}
if(s==4) {
System.out.print("正在进入删除货物入口");
try {
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
System.out.println("");
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("请输入编号删除货物:");
int s1=sc.nextInt();
for(int i=0;i<m.length;i++) {
if(m[i].getId()==s1) {
m[i]=null;
System.out.println("删除成功");
}else {
System.out.println("没有找到该编号");
}
}
}
if(s==5) {
System.out.print("正在退出");
try {
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
Thread.sleep(300);
System.out.print(".");
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
break;
}
if(s>5||s<1) {
System.out.println("请输入对应的编号");
}
}
}
}