/**
* 超市管理系统
* @author Administrator
*
*/
public class ChaoShiSystemManager {
public static void main(String[] args) {
new HuoWuDomImpl().start();
}
}
class HuoWu{
public String bianhao; //商品编号
public String name; //商品名称
public double jiage; //商品价格
}
class HuoWuDomImpl{
private static java.util.ArrayListlist = new java.util.ArrayList ();
public void start(){
int num = 0;
System.out.println("--欢迎登录超市管理系统--");
System.out.println("1、添加商品");
System.out.println("2、查询商品");
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("请输入模块名称:");
try {
num = sc.nextInt();
if(num == 1){
setHuoWu();
new HuoWuDomImpl().start();
}else if(num == 2){
getSeleteHuoWu();
new HuoWuDomImpl().start();
}else{
throw new RuntimeException("提示:抱歉,模块正在开发中");
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("提示:对不起,您的输入有误!");
}finally{
sc.close();
}
}
public void setHuoWu(){
HuoWu hw = new HuoWu();
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("请输入商品编号:");
hw.bianhao = sc.next();
System.out.println("请输入商品名称:");
hw.name = sc.next();
System.out.println("请输入商品价格");
try {
hw.jiage = sc.nextDouble();
} catch (Exception e) {
throw new RuntimeException("提示:商品价格输入错误!");
}finally{
sc.close();
}
list.add(hw);
System.out.println("提示:恭喜,添加成功!");
}
public void getSeleteHuoWu(){
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println("请输入商品编号...");
String bianhao = sc.next();
java.util.Iterator it = list.iterator();
while(it.hasNext()){
if(bianhao.equals(((HuoWu)it.next()).bianhao)){
System.out.println("商品编号:" + ((HuoWu)it.next()).bianhao);
System.out.println("商品名称:" + ((HuoWu)it.next()).name);
System.out.println("商品价格:" + ((HuoWu)it.next()).jiage);
}
}
}
}
PS:程序可能还有点问题,自己调试一下吧。改天有空我再来更新。