1. 程式人生 > >JAVA肯德基快餐店收銀系統

JAVA肯德基快餐店收銀系統

題目: 同學們應該都去麥當勞或肯德基吃過快餐吧?請同學們參考肯德基官網的資訊模擬肯德基快餐店的收銀系統,合理使用C++/python/Java,結合設計模式(2種以上)至少實現系統的以下功能: 1.正常餐品結算和找零。 2.基本套餐結算和找零。 3.使用優惠劵購買餐品結算和找零。 4.可在一定時間段參與店內活動(自行設計或參考官網資訊)。 5.模擬列印小票的功能(寫到檔案中)。 用時2周。 基本要求: 1.程式設計風格良好,控制檯介面友好,最多兩人一組完成任務。 2.實現功能測試程式碼,確保程式的健壯性。 3.畫出使用的設計模式圖。 提高要求: 1.實現視覺化介面。 2.實現會員儲值卡功能,完成儲值卡消費。 3.實現當天營業額和餐品銷量計算和統計,用資料庫記錄。

package KFC;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import java.util.ArrayList;

public class KFC {
		static    int  mymoney = 0 ;        //已點餐的價錢
		//static   String[]   myfood = new String[] {} ;                //已點食物   購物車
		static ArrayList<String> arr=new ArrayList<>();
		static int i = 0;
		static Map<String,Integer>  zhushimap = new HashMap();
		static Map<String,Integer>  fushimap = new HashMap();
		static  Map<String,Integer>  drinkmap = new HashMap();
		static  Map<String,Integer>  taocanmap = new HashMap();
	public static void main(String[] arges) 
	{
		
		     zhushimap.put("香辣雞腿堡",14);
		     zhushimap.put("叮咚雞塊",8);
		     zhushimap.put("脆皮雞腿",8); 
		     fushimap.put("乳酪棒", 7);
		     fushimap.put("大薯條", 9);
		     fushimap.put("骨肉相連", 7);
		     drinkmap.put("港式奶茶", 7);
		     drinkmap.put("橙C", 7);
		     taocanmap.put("香辣雞腿堡+脆皮雞腿+港式奶茶", 26);
		     taocanmap.put("叮咚雞塊+大薯條+橙C", 22);
		menu();
	};
public static void choosezhushi()               //選主食
{
	System.out.print("                                                            \n");
	System.out.print("         ***********************************    \n");
	System.out.print("                  請選擇服務型別                   \n");
	System.out.print("\n                    1.香辣雞腿堡                  "+zhushimap.get("香辣雞腿堡"));
	System.out.print(" \n                   2.叮咚雞塊                     "+zhushimap.get("叮咚雞塊"));
	System.out.print("\n                    3.脆皮雞腿                     "+zhushimap.get("脆皮雞腿"));
	System.out.print("\n                       4.返回                              \n\n");
	System.out.print(" \n     ************************************                              \n");
	Scanner input = new Scanner(System.in);
	int n = input.nextInt();
	switch (n) {
	case 1:
		//myfood[i]="香辣雞腿堡";
		arr.add("香辣雞腿堡");
		mymoney+=zhushimap.get("香辣雞腿堡");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 2:
		//myfood[i]="叮咚雞塊";
		arr.add("叮咚雞塊");
		mymoney+=zhushimap.get("叮咚雞塊");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 3:
		//myfood[i]="脆皮雞腿";
		arr.add("脆皮雞腿");
		mymoney+=zhushimap.get("脆皮雞腿");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 4:
		order();
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			choosezhushi();
			}
	choosezhushi();

		}
public static void choosefushi()               //選副食
{
	System.out.print("                                                            \n");
	System.out.print("         ***********************************    \n");
	System.out.print("                  請選擇服務型別                   \n");
	System.out.print("\n                    1.乳酪棒                  "+fushimap.get("乳酪棒"));
	System.out.print(" \n                   2.大薯條                     "+fushimap.get("大薯條"));
	System.out.print("\n                    3.骨肉相連                     "+fushimap.get("骨肉相連"));
	System.out.print("\n                       4.返回                              \n\n");
	System.out.print(" \n     ************************************                              \n");
	Scanner input = new Scanner(System.in);
	int n = input.nextInt();
	switch (n) {
	case 1:
		//myfood[i]="乳酪棒";
		arr.add("乳酪棒");
		mymoney+=fushimap.get("乳酪棒");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 2:
		//myfood[i]="大薯條";
		arr.add("大薯條");
		mymoney+=fushimap.get("大薯條");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 3:
		//myfood[i]="骨肉相連";
		arr.add("骨肉相連");
		mymoney+=fushimap.get("骨肉相連");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 4:
		order();
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			choosefushi();
			}
	choosefushi();
		}

public static void choosedrink()               //選飲料
{
	System.out.print("                                                            \n");
	System.out.print("         ***********************************    \n");
	System.out.print("                  請選擇服務型別                   \n");
	System.out.print("\n                    1.港式奶茶                  "+drinkmap.get("港式奶茶"));
	System.out.print(" \n                   2.橙C                     "+drinkmap.get("橙C"));
	System.out.print("\n                    3.返回                              \n\n");
	System.out.print(" \n     ************************************                              \n");
	Scanner input = new Scanner(System.in);
	int n = input.nextInt();
	switch (n) {
	case 1:
		//myfood[i]="港式奶茶";
		arr.add("港式奶茶");
		mymoney+=drinkmap.get("港式奶茶");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 2:
		//myfood[i]="橙C";
		arr.add("橙C");
		mymoney+=drinkmap.get("橙C");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 3:
		order();
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			choosedrink();
			}
	choosedrink();

		}

public static void choosetaocan()               //選套餐
{
	System.out.print("                                                            \n");
	System.out.print("         ***********************************    \n");
	System.out.print("                  請選擇套餐型別                   \n");
	System.out.print("\n      1.香辣雞腿堡+脆皮雞腿+港式奶茶            "+taocanmap.get("香辣雞腿堡+脆皮雞腿+港式奶茶"));
	System.out.print(" \n     2.叮咚雞塊+大薯條+橙C                     "+taocanmap.get("叮咚雞塊+大薯條+橙C"));
	System.out.print("\n                    3.返回                              \n\n");
	System.out.print(" \n     ************************************                              \n");
	Scanner input = new Scanner(System.in);
	int n = input.nextInt();
	switch (n) {
	case 1:
		//myfood[i]="香辣雞腿堡+脆皮雞腿+港式奶茶";//   i 沒有初始值
		arr.add("香辣雞腿堡+脆皮雞腿+港式奶茶");
		mymoney+=taocanmap.get("香辣雞腿堡+脆皮雞腿+港式奶茶");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 2:
		System.out.println(i);
		//myfood[i]="叮咚雞塊+大薯條+橙C";
		arr.add("叮咚雞塊+大薯條+橙C");
		mymoney+=taocanmap.get("叮咚雞塊+大薯條+橙C");
		System.out.print(" \n   您已選擇成功!                 \n");
		//i++;
		break;
	case 3:
		order();
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			choosetaocan( );
			}
	choosetaocan();
		}


	public static void order()     //點餐
	{
		System.out.print("                                                            \n");
		System.out.print("      ***********************************    \n");
		System.out.print("                  請選擇服務型別                   \n");
		System.out.print("                    1.主食                              \n");
		System.out.print("                    2.副食                           \n");
		System.out.print("                    3.飲料                             \n");
		System.out.print("                    4.套餐                              \n");
		System.out.print("                    5.退出                              \n\n");
		System.out.print("      ************************************                              \n");
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		switch (n) {
		case 1:
			choosezhushi();
			break;
		case 2:
			choosefushi();
			break;
		case 3:
			choosedrink();
			break;
		case 4:
			choosetaocan();
			break;
		case 5:
			menu();
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			menu();}
		}

	public static void viewShoppingcart() // 檢視購物車
	{
		System.out.print("                                                             \n");
		System.out.print("       ***********************************    \n\n");
		System.out.print("           您的購物車中共有食物"+arr.size()+"件");
		System.out.print("                 具體如下             \n");
		for(String name:arr)
			System.out.println(name);
    		System.out.print("       ***********************************    \n\n");
    		menu();
	}

	
	public static void cleanShoppingcart() // 清空購物車
	{
       arr.clear();
       mymoney = 0;
       System.out.print("           您已成功清空購物車");
       menu();
	}

	public static void settlement() // 結算
	{
		System.out.print("                                                             \n");
		System.out.print("       ***********************************    \n\n");
		System.out.print("              請選擇支付型別               \n\n");
		System.out.print("                 1.優惠券支付             \n");
		System.out.print("                 2.直接支付               \n\n");
		System.out.print("       ***********************************    \n\n");
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		switch (n) {
		case 1:
			discountCoupon();
			break;
		case 2:
	          payment();
			break;
			default:
			    System.out.println("\n 您的輸入有誤,請按任意鍵重新選擇!\n");
			    Scanner input2 = new Scanner(System.in);
				int m = input2.nextInt();
				menu();
			}
		
	}
	
	public static void discountCoupon()                  //優惠券
	{
		  System.out.println("\n 請輸入您的優惠券\n");
		  Scanner input3 = new Scanner(System.in);
			int  yhq = input3.nextInt();
		  if(yhq==123456) {
			  mymoney-=5;
			  System.out.println("優惠過的價格"+mymoney);
			  payment();
		  }else {
			  System.out.println("\n 對不起,您的優惠券無效!\n");
		  }
		  settlement();
	}

	public static void payment()                            //支付
	{
		 System.out.println("\n 您本次消費"+mymoney);
		 System.out.println("\n 請輸入您的付款面額");
			Scanner input = new Scanner(System.in);
			int n = input.nextInt();
			int p=n-mymoney;
			if(p<0) {
				 System.out.println("\n 您付的現金不足,還需要"+(0-p)+"元,請繼續支付現金!");
			}
		 System.out.println("\n 支付成功,找零"+p+"元!祝您生活愉快!");
		 menu();
	}
	
	public static void menu() {                              //選單

		System.out.print("                                                            \n");
		System.out.print("      ***********************************    \n");
		System.out.print("                  請選擇服務型別               \n\n");
		System.out.print("                    1.點餐                          \n");
		System.out.print("                    2.檢視購物車               \n");
		System.out.print("                    3.清空購物車                     \n");
		System.out.print("                    4.結算                              \n");
		System.out.print("                    5.退出                              \n\n");
		System.out.print("      ************************************                              \n");
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		switch (n) {
		case 1:
			order();
			break;
		case 2:
			viewShoppingcart();
			break;
		case 3:
			cleanShoppingcart();
			break;
		case 4:
			settlement();
			break;
		case 5:
			System.exit(0);
		default:
			System.out.print(" \n          您輸入有誤,請按任意鍵重新選擇            \n");
			Scanner input1 = new Scanner(System.in);
			int m = input.nextInt();
			menu();
		}

	}

}