寫留的商務超市管理系統~~~第一部分

來源:互聯網
上載者:User

標籤:商超 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("**********我是分割線***********");}}

然後我的思路非常線性,寫了寫架構在紙上,大概就是兩個東西,一個叫salesman,用來操作物品,一個叫做good,就是物品。

我用一個叫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"));} elseSystem.out.println("商品不存在,請核實!");}// 查看指定商品public void query() {System.out.println("請輸入商品名稱:");String name = in.next();if (Goods.goodMap.get(name) != null) {gm.query(name);} elseSystem.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);} elseSystem.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"));} elseSystem.out.println("使用者名稱不存在!");}// 刪除售貨員public void deleteSalesman() {System.out.println("請輸入要刪除的使用者名稱:");String name = in.next();if (SalesmanGroup.userMap.get(name) != null) {SalesmanGroup.userMap.remove(name);} elseSystem.out.println("使用者名稱不存在!");}// 尋找指定售貨員public void querySalesman() {System.out.println("請輸入要查詢的使用者名稱:");String name = in.next();if (SalesmanGroup.userMap.get(name) != null) {sm.query(name);} elseSystem.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();}}

先寫到這裡,具體的底層操作請見下一步!

寫留的商務超市管理系統~~~第一部分

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.