package com.company; class commodity { private int id; private String name; private int price; int number; public commodity(int id,String name,int price,int number){ this.id=id; this.name=name; this.price=price; this.number=number; } public commodity(){} public commodity(int i){ Person.goods=new commodity[i]; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } }
package com.company; import java.util.Scanner; class admin extends Person implements operate{ public admin(){ super(); } Scanner sc = new Scanner(System.in); public void operate(){ System.out.println("请输入确认操作:"); int i =sc.nextInt(); switch (i){ case 1: select(goods); break; case 2: add(goods); break; case 3: delete(goods); break; case 4: modify(goods); break; default: System.out.println("输入有误!"); break; } } public void select(commodity[]goods){ System.out.println("请输入名称进行查询:"); String name = sc.next(); if (name!=null){ for (int i = 0;i<goods.length;i++){ if (goods[i].getName().equals(name)){ System.out.println("有此商品"); System.out.println("商品信息为:(编号-名称-价格-数量)"); System.out.println(goods[i].getId()+" "+goods[i].getName()+" "+goods[i].getPrice()+" "+goods[i].getNumber()); break; } while (i== goods.length-1){ System.out.println("暂时没有此商品!"); break;} } }else{ System.out.println("暂时没有该商品!"); } } public void delete(commodity[]goods){ System.out.println("请输入要删除的商品:"); String str =sc.next(); if (str!=null){ for (int i =0;i< goods.length;i++){ if (goods[i].getName().equals(str)){ goods[i]=null; System.out.println("删除成功!"); System.out.println(goods.length); break; } } } } public void add(commodity[]goods){ System.out.println("请输入商品编号:"); int id=sc.nextInt(); System.out.println("请输入商品名称:"); String name =sc.next(); System.out.println("请输入价格:"); int price=sc.nextInt(); System.out.println("请输入数量:"); int number=sc.nextInt(); for (int i =0;i< goods.length;i++){ if (goods[i].getId()!=0){ goods[i].setId(id); goods[i].setName(name); goods[i].setPrice(price); goods[i].setNumber(number); System.out.println("添加成功"); break; } } } public void modify(commodity[]goods){ System.out.println("请输入要修改商品的名称:"); String a = sc.next(); for (int i =0;i<goods.length;i++){ if (goods[i].getName().equals(a)) { System.out.println("请输入修改后的价格:"); int s = sc.nextInt(); goods[i].setPrice(s); System.out.println("修改成功!"); break; } } } }
package com.company; import java.util.Scanner; public class Store { Scanner sc = new Scanner(System.in); public void login(){ int count =0; Person p = null; while(count<2){ System.out.println("==============商品管理系统==============="); System.out.println("请登录:1.顾客 2.管理员 0.退出系统"); int n =sc.nextInt(); if (n==0){ return; } switch (n){ case 1 : p=new customers(); System.out.println("用户登录成功!"); while(true){ System.out.println("请输入你的操作: 1.查找商品 2.购买商品 3.离开"); int i = sc.nextInt(); if (i==3){ System.out.println("您已经成功离开超市!"); break; }else{ p.operate(); } } break; case 2 : p=new admin(); System.out.println("管理员登录成功!"); while(true){ System.out.println("请输入你的操作:1.查看商品 2.增加商品 3.删除商品 4.修改 5.退出"); int j =sc.nextInt(); if (j==5){ System.out.println("您已经成功退出"); break; }else{ p.operate(); } } break; } } } }
package com.company; import java.util.Scanner; class customers extends Person implements operate{ public customers(){ super(); } Scanner sc =new Scanner(System.in); public void operate(){ System.out.println(“请输入您的操作:”); int i = sc.nextInt(); switch (i){ case 1 : select(goods); break; case 2 : delete(goods); break; default: System.out.println(“输入有误!”); break; } } public void select(commodity[]goods){ System.out.println(“请输入商品名称查询:”); String name = sc.next(); if (name!=null){ for (int i =0;i if (goods[i].getName().equals(name)){ System.out.println(“有此商品!”); System.out.println(“商品信息为:(编号-名称-价格-数量)”); System.out.println(goods[i].getId()+" “+goods[i].getName()+” “+goods[i].getPrice()+” "+goods[i].getNumber()); break; }while (igoods.length-1){ System.out.println(“暂时没有该商品!”); break;} } } } public void delete(commodity[]goods){ System.out.println(“请输入将要买的商品:”); String name=sc.next(); if (name!=null){ for (int i =0;i< goods.length-1;i++){ if (goods[i].getName().equals(name)){ System.out.println(“购买成功!”); goods[i].setNumber(goods[i].getNumber()-1); break; }while (i goods.length-1){ System.out.println(“没有该商品!”); break; } } } }
@Override public void add(commodity[] goods) { } @Override public void modify(commodity[] goods) { } }