1. 程式人生 > >java新手----超市管理系統--殘章(沒寫完,不過後面的會員管理和買東西寫完了)

java新手----超市管理系統--殘章(沒寫完,不過後面的會員管理和買東西寫完了)

https://download.csdn.net/download/shui_jin_shan/10798218

上面是我放的程式碼地址:

下面我的welcome的程式碼:

/**
 * 
 */
package supermarket;

import java.util.Scanner;

/**
 * @author Administrator 歡迎介面
 */
public class Welcome {

	public static void main(String[] args) {
		Supermarket supermarket = new Supermarket("大潤發");
		Shelf[] shelfs = new Shelf[3];// 貨架3個
		Goods[] goods = new Goods[5];// 每個貨架的商品數最大5
		int[] countOfShelf = new int[3];// 統計每個貨架的商品數
		shelfs[0] = new Shelf("食物", 0);
		shelfs[1] = new Shelf("衣物", 1);
		shelfs[2] = new Shelf("日用品", 2);

		goods[0] = new Goods(0, "薯片", "樂事", 99, "2018年11月20日", 4.5, 3.5);
		goods[1] = new Goods(1, "方便麵", "康師傅", 99, "2018年11月20日", 3.5, 2.5);
		countOfShelf[0] = 2;
		shelfs[0].setGoods(goods);
		goods = new Goods[5];
		goods[0] = new Goods(0, "衛衣", "美特斯邦威", 50, "2018年11月20日", 150.0, 130.0);
		goods[1] = new Goods(1, "運動褲", "耐克", 50, "2018年11月20日", 140.0, 120.0);
		countOfShelf[1] = 2;
		shelfs[1].setGoods(goods);
		goods = new Goods[5];
		goods[0] = new Goods(0, "香皂", "舒膚佳", 50, "2018年11月20日", 10.0, 8.0);
		goods[1] = new Goods(1, "洗髮露", "海飛絲", 50, "2018年11月20日", 15.0, 12.0);
		countOfShelf[2] = 2;
		shelfs[2].setGoods(goods);

		supermarket.setShelfs(shelfs);
		// 初始化超市商品-------------------------------------------------------------------------------------

		while (true) {
			// 先初始化使用的變數
			boolean isExit = false;// 判斷是否退出
			int key = -1;// 選項輸入初始化
			int cardId = 0;// 會員卡號初始化
			int credit = 0;// 會員積分初始化
			double totalCost = 0;// 總花費初始化
			Goods[] goodssOfNew = null;// 購買選項貨物列表初始化
			double priceOfGoods = 0;// 商品價格初始化
			int idOfGoods = -1;// 商品編號初始化
			int countOfBuy = 0;// 購買數量初始化
			int getCountOfGoods = 0;// 貨架物品數量初始化
			// ----------------------------------------------------------------------------------------
			System.out.println("歡迎進入大潤發超市管理系統介面");
			System.out.println("--------------------");
			System.out.println("選項\t專案名稱");
			System.out.println("1.\t商品管理");
			System.out.println("2.\t員工管理");
			System.out.println("3.\t會員管理");
			System.out.println("4.\t購買操作");
			System.out.println("按其他鍵退出");
			System.out.println("--------------------");
			Scanner input = new Scanner(System.in);
			System.out.println("請輸入選擇:");
			switch (input.nextInt()) {
			case 1:

				while (true) {
					System.out.println("選項\t內容");
					System.out.println("-------------------");
					System.out.println("1.\t商品新增");
					System.out.println("2.\t商品刪除");
					System.out.println("3.\t商品查詢");
					System.out.println("or 按任意鍵退出");
					System.out.println("-------------------");
					System.out.println("請輸入:");
					key = input.nextInt();
					switch (key) {
					case 1:

						break;
					case 2:

						break;
					case 3:

						break;

					default:
						isExit = true;
						break;
					}
					if (isExit) {
						break;
					}

				}

				break;
			case 2:

				break;
			case 3:

				while (true) {
					System.out.println("選項\t內容");
					System.out.println("-------------------");
					System.out.println("1.\t檢視會員資訊");
					System.out.println("2.\t新增會員");
					System.out.println("3.\t刪除會員");
					System.out.println("or 按任意鍵退出");
					System.out.println("-------------------");
					System.out.println("請輸入:");
					key = input.nextInt();
					switch (key) {
					case 1:
						System.out.println("請輸入想要檢視的會員卡號");
						cardId = input.nextInt();
						Card.query(cardId);
						break;
					case 2:
						Card.add();
						break;
					case 3:
						System.out.println("請輸入需要刪除的會員卡號");
						cardId = input.nextInt();
						Card.delete(cardId);
						break;

					default:
						isExit = true;
						break;
					}
					if (isExit) {
						break;
					}

				}

				break;
			case 4:
				while (true) {
					System.out.println("歡迎光臨" + supermarket.getmName());
					System.out.println("貨架列表如下:");
					System.out.println("貨架編號\t貨架型別");
					Shelf[] she = supermarket.getShelfs();
					for (int i = 0; i < she.length; i++) {
						System.out.println(she[i].getShelfId() + "\t" + she[i].getShelfName());

					}

					System.out.println("請選擇貨架編號:");
					key = input.nextInt();
					switch (key) {
					case 0:
						System.out.println("有以下商品:");
						System.out.println("商品編號\t商品名稱\t商品價格");
						goodssOfNew = she[0].getGoods();
						getCountOfGoods = countOfShelf[0];
						for (int i = 0; i < getCountOfGoods; i++) {
							System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
									+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
						}

						System.out.println("請輸入商品編號:");
						idOfGoods = input.nextInt();
						for (int i = 0; i < getCountOfGoods; i++) {
							if (idOfGoods == goodssOfNew[i].getgId()) {
								priceOfGoods = goodssOfNew[i].getgPrice();
							}
						}
						System.out.println("請輸入數量:");
						countOfBuy = input.nextInt();
						totalCost += priceOfGoods * countOfBuy;

						break;
					case 1:
						System.out.println("有以下商品:");
						System.out.println("商品編號\t商品名稱\t商品價格");
						goodssOfNew = she[1].getGoods();
						getCountOfGoods = countOfShelf[1];
						for (int i = 0; i < getCountOfGoods; i++) {
							System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
									+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
						}

						System.out.println("請輸入商品編號:");
						idOfGoods = input.nextInt();
						for (int i = 0; i < getCountOfGoods; i++) {
							if (idOfGoods == goodssOfNew[i].getgId()) {
								priceOfGoods = goodssOfNew[i].getgPrice();
							}
						}
						System.out.println("請輸入數量:");
						countOfBuy = input.nextInt();
						totalCost += priceOfGoods * countOfBuy;

						break;
					case 2:
						System.out.println("有以下商品:");
						System.out.println("商品編號\t商品名稱\t商品價格");
						goodssOfNew = she[2].getGoods();
						getCountOfGoods = countOfShelf[2];
						for (int i = 0; i < getCountOfGoods; i++) {
							System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
									+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
						}

						System.out.println("請輸入商品編號:");
						idOfGoods = input.nextInt();
						for (int i = 0; i < getCountOfGoods; i++) {
							if (idOfGoods == goodssOfNew[i].getgId()) {
								priceOfGoods = goodssOfNew[i].getgPrice();
							}
						}
						System.out.println("請輸入數量:");
						countOfBuy = input.nextInt();
						totalCost += priceOfGoods * countOfBuy;

						break;

					default:
						isExit = true;
						break;
					}

					System.out.println("請輸入您的會員卡號,沒有請按0");
					key = input.nextInt();
					for (int i = 0; i < Card.numOfCards; i++) {
						if (key == 0) {
							break;
						}
						if (key == Card.cards[i].getCardId()) {
							cardId = key;
							break;
						}
					}
					System.out.println("您總共消費 " + totalCost + " 元");
					if (cardId != 0) {
						Card.setCredit((int) totalCost, cardId);
						credit = Card.getCredit(cardId);
						System.out.println("您當前擁有積分 " + credit);
					}
					System.out.println("是否要繼續購買?繼續請按1,結賬請按2");
					key = input.nextInt();
					if (key == 2) {
						System.out.println("您需要付" + (totalCost - credit / 100) + " 元");
						credit -= credit / 100 * 100;
						Card.setCredit(credit, cardId);
						if (cardId != 0) {
							System.out.println("您還剩積分 " + Card.getCredit(cardId));
						}
						try {
							Thread.sleep(5000);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						isExit = true;
					}

					if (isExit) {

						break;
					}

				}

				break;

			default:
				System.exit(0);
			}

		}

	}

}