标签:商超 java
需求请见:http://pan.baidu.com/s/1pJPsYF5
有机会希望再补po到blog上面~
首先用menu把进入后的框架搭起来
/* * 各级菜单显示 */ package com.pb.menu; public class Menu { /** * 登陆菜单 */ public void login() { System.out.println("欢迎使用商超管理系统"); System.out.println("1、登陆系统"); System.out.println("2、退出"); } /** * 主菜单内容 */ public void mainMenu() { System.out.println("**********我是分割线***********"); System.out.println("1、商品维护"); System.out.println("2、前台收银"); System.out.println("3、商品管理"); System.out.println("4、返回上一级菜单"); System.out.println("**********我是分割线***********"); } /** * 商品维护菜单内 容 */ public void mainMenu_1() { 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("5、查询商品信息"); System.out.println("6、入库管理"); System.out.println("7、保存"); System.out.println("8、返回上一级菜单"); System.out.println("**********我是分割线***********"); } /** * 前台收银菜单内容 */ public void mainMenu_2() { System.out.println("商超购物系统>>>前台收银"); System.out.println("**********我是分割线***********"); System.out.println("1、购物结算"); System.out.println("2、返回上一级菜单"); System.out.println("**********我是分割线***********"); } /** * 商品维护菜单内容 */ public void mainMenu_3() { 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("**********我是分割线***********"); } public void mainMenu_3_3() { 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("5、查看售货员信息"); System.out.println("6、保存"); System.out.println("7、返回上一级菜单"); System.out.println("**********我是分割线***********"); } }
我用一个叫user的类去管理存储他们两个的方法和属性。然后再分别去管理调用
于是我先把main函数写出来,然后就每个缺少的部分再去写他们每个的内容。
package com.pb.user; import java.util.Scanner; import com.pb.good.Good; import com.pb.goodbiz.Goods; import com.pb.isinputright.IsRight; import com.pb.management.GoodManagement; import com.pb.management.SalesmanManagement; import com.pb.myexception.MyException; import com.pb.salesman.Salesman; import com.pb.salesmanBiz.SalesmanGroup; public class User { Scanner in = new Scanner(System.in); GoodManagement gm = new GoodManagement(); SalesmanManagement sm = new SalesmanManagement(); //登陆主菜单 public boolean landingMan(){ System.out.print("请输入用户名:"); String name = in.next(); System.out.print("\n请输入密码:"); String psd = in.next(); if(name.equals("admin")){ if(psd.equals("admin")) return true; } return false; } // 售货员登陆登陆 public boolean landing() { System.out.print("请输入用户名:"); String name = in.next(); System.out.print("\n请输入密码:"); String psd = in.next(); try { if (SalesmanGroup.userMap.get(name) == null) throw new MyException("用户名密码不匹配!"); } catch (MyException e) { System.out.println(e.getMessage()); return false; } try { if (!SalesmanGroup.userMap.get(name).getPsd().equals(psd)) throw new MyException("用户名密码不匹配!"); } catch (MyException e) { System.out.println(e.getMessage()); return false; } return true; } // 新增商品 public void add() { System.out.println("请输入商品信息:"); System.out.println("请输入商品名称:"); String name = in.next(); try { if (Goods.goodMap.get(name) != null) throw new MyException("用户名已存在!"); } catch (MyException e) { System.out.println(e.getMessage()); return; } System.out.println("请输入商品价格:"); double price = in.nextDouble(); System.out.println("请输入商品库存:"); int storage = in.nextInt(); gm.add(new Good(name, price, storage)); } // 删除商品 public void delete() { System.out.println("请输入商品名称:"); String name = in.next(); if (Goods.goodMap.get(name) != null) { if (Goods.goodMap.get(name).getStorage() == 0) { gm.delete(name); } else { System.out.println("库存不为0,不能删除商品!"); } } else { System.out.println("商品不存在!"); } } // 修改商品 public void modify() { System.out.println("请输入商品名称:"); String name = in.next(); if (Goods.goodMap.get(name) != null) { gm.query(name); String c; do { System.out.println("请选择您要修改的内容:"); System.out.println("1、更改商品名称:"); System.out.println("2、更改商品价格:"); System.out.println("3、更改商品数量:"); int n = in.nextInt(); switch (n) { case 1: System.out.println("请输入变更后的商品名称:"); String newname = in.next(); Good good = Goods.goodMap.get(name); good.setName(newname); Goods.goodMap.remove(name); Goods.goodMap.put(newname, good); break; case 2: System.out.println("请输入变更后的商品价格:"); Goods.goodMap.get(name).setPrice(in.nextDouble()); break; case 3: System.out.println("请输入变更后的商品数量:"); Goods.goodMap.get(name).setStorage(in.nextInt()); break; } System.out.print("是否继续修改此商品信息(N/Y):"); c = in.next(); } while (c.equalsIgnoreCase("y")); } else System.out.println("商品不存在,请核实!"); } // 查看指定商品 public void query() { System.out.println("请输入商品名称:"); String name = in.next(); if (Goods.goodMap.get(name) != null) { gm.query(name); } else System.out.println("商品不存在,请核实!"); } // 按价格升序查询 public void priceQuery() { gm.priceQuery(); } // 查看全部商品 public void queryAll() { gm.queryAll(); } // 查询当日买出商品 public void dayQuery() { gm.dayQuery(); } // 模糊查找商品信息 public boolean fuzzyQuery() { System.out.println("请输入商品关键字:"); String str = in.next(); return gm.fuzzyQuery(str); } // 保存商品信息 public void save() { gm.save(); } // 商品入货 public void in() { System.out.println("请输入商品名称:"); String name = in.next(); if (Goods.goodMap.get(name) != null) { System.out.println("请输入入库数量:"); int num = in.nextInt(); gm.in(name, num); } else System.out.println("商品不存在!"); } // 新增售货员 public void addSalesman() { System.out.println("请输入售货员信息:"); System.out.println("请输入用户名:"); String name = in.next(); try { if (SalesmanGroup.userMap.get(name) != null) throw new MyException("该用户已存在!"); } catch (MyException e) { System.out.println(e.getMessage()); return; } System.out.println("请输入密码:"); String psd = in.next(); if (!IsRight.isPsd(psd)) return; System.out.println("请再次输入密码:"); String psd1 = in.next(); if (!IsRight.isPsd(psd, psd1)) return; System.out.println("请输入年龄:"); int age = in.nextInt(); if (!IsRight.isAge(age)) return; sm.add(new Salesman(name, psd, age)); } // 修改售货员 public void modifySalesman() { System.out.println("请输入用户名:"); String name = in.next(); if (SalesmanGroup.userMap.get(name) != null) { sm.query(name); String c; do { System.out.println("请选择您要修改的内容:"); System.out.println("1、更改用户名:"); System.out.println("2、更改密码:"); System.out.println("3、更改年龄:"); int n = in.nextInt(); switch (n) { case 1: System.out.println("请输入变更后的用户名"); String newname = in.next(); Salesman salesman = SalesmanGroup.userMap.get(name); salesman.setName(newname); SalesmanGroup.userMap.remove(name); SalesmanGroup.userMap.put(newname, salesman); break; case 2: System.out.println("请输入变更后的密码:"); SalesmanGroup.userMap.get(name).setPsd(in.next()); break; case 3: System.out.println("请输入变更后的年龄:"); SalesmanGroup.userMap.get(name).setAge(in.nextInt()); break; } System.out.print("是否继续修改此用户信息(N/Y):"); c = in.next(); } while (c.equalsIgnoreCase("y")); } else System.out.println("用户名不存在!"); } // 删除售货员 public void deleteSalesman() { System.out.println("请输入要删除的用户名:"); String name = in.next(); if (SalesmanGroup.userMap.get(name) != null) { SalesmanGroup.userMap.remove(name); } else System.out.println("用户名不存在!"); } // 查找指定售货员 public void querySalesman() { System.out.println("请输入要查询的用户名:"); String name = in.next(); if (SalesmanGroup.userMap.get(name) != null) { sm.query(name); } else System.out.println("用户名不存在!"); } // 查找全部售货员 public void queryAllSalesman() { sm.queryAll(); } // 保存 public void saveSalesman() { sm.save(); } // 检查商品库存 public void checkStorage(int num) { gm.checkStorage(num); } // 购物 public double settlement() { System.out.println("请输入商品名称:"); String name = in.next(); if (Goods.goodMap.get(name) == null) { System.out.println("商品不存在!"); return 0; } else { System.out.println("请输入购买数量:"); int sale = in.nextInt(); return gm.settlement(Goods.goodMap.get(name), sale); } } // 付款 public void payment() { double sum = 0;// 购买商品总金额 double sum1 = 0;// 总交费金额 double money = 0;// 单次交费金额 String c; do { if (fuzzyQuery()) { sum += settlement(); } else { System.out.println("商品不存在!"); } System.out.print("是否继续购买(N/Y):"); c = in.next(); } while (c.equalsIgnoreCase("y")); if (sum == 0) System.out.println("欢迎再次光临"); else { do { System.out.println("请输入交费金额:"); money = in.nextDouble(); sum1 += money; if (sum1 < sum) System.out.println("交费金额小于货款,请继续交费!"); } while (sum1 < sum); System.out.println("找钱:" + (sum1 - sum) + "\n欢迎再次光临"); } } }然后我们再去写他们的Management
——————————————————华丽的分割线——————————————————————
/** * 管理商品信息库 */ package com.pb.management; import com.pb.good.Good; import com.pb.goodbiz.Goods; public class GoodManagement { Goods goods = new Goods(); // 新增 public void add(Good good) { goods.addGood(good); } // 删除 public void delete(String name) { goods.deleteGood(name); } // 修改 public void modify(Good good) { goods.modifyGood(good); } // 查询指定商品 public void query(String name) { goods.queryGood(name); } // 查询全部商品 public void queryAll() { goods.queryAll(); } // 查询当日买出商品 public void dayQuery() { goods.dayQuery(); } // 升序查找商品 public void priceQuery() { goods.priceQuery(); } // 模糊查找商品信息 public boolean fuzzyQuery(String str) { return goods.fuzzyQuery(str); } // 保存 public void save() { goods.save(); } // 入库 public void in(String name, int num) { goods.in(name, num); } // 检查商品库存 public void checkStorage(int num) { goods.checkStorage(num); } // 结账 public double settlement(Good good, int sale) { return goods.settlement(good, sale); } }
/** * 管理售货员库 */ package com.pb.management; import com.pb.salesman.Salesman; import com.pb.salesmanBiz.SalesmanGroup; public class SalesmanManagement { SalesmanGroup sg = new SalesmanGroup(); // 新增售货员 public void add(Salesman user) { sg.add(user); } // 修改售货员 public void modity(Salesman user) { sg.modify(user); } // 删除售货员 public void delete(String name) { sg.delete(name); } // 查找指定售货员 public void query(String name) { sg.query(name); } // 查找全部售货员 public void queryAll() { sg.queryAll(); } //保存 public void save(){ sg.save(); } }
标签:商超 java
原文地址:http://blog.csdn.net/qbt4juik/article/details/41901769