java實(shí)現(xiàn)KFC點(diǎn)餐小程序
本文實(shí)例為大家分享了java實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
package KFC點(diǎn)餐系統(tǒng);
//food 類(lèi)
public class Kfcfood {
private String fname ;
private int fnumb=1;
private float fPrice;
public Kfcfood() {
super();
}
public Kfcfood(String fname, int fnumb, float fPrice) {
super();
this.fname = fname;
this.fnumb = fnumb;
this.fPrice = fPrice;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public int getFnumb() {
return fnumb;
}
public void setFnumb(int fnumb) {
this.fnumb = fnumb;
}
public float getfPrice() {
return fPrice*fnumb;
}
public void setfPrice(float fPrice) {
this.fPrice = fPrice;
}
@Override
public String toString() {
return fname + " 價(jià)格 [" + fPrice + "]";
}
}
package KFC點(diǎn)餐系統(tǒng);
/*
* 1.正常餐品結(jié)算和找零。
2.基本套餐結(jié)算和找零。
3.使用優(yōu)惠劵購(gòu)買(mǎi)餐品結(jié)算和找零。
4.可在一定時(shí)間段參與店內(nèi)活動(dòng)(自行設(shè)計(jì)或參考官網(wǎng)信息)。
5.模擬打印小票的功能(寫(xiě)到文件中)。
* */
/*@author:kxd
* @Date:2018.10.25
*
* 本人寫(xiě)這個(gè)小程序,第一創(chuàng)建Kfcfood類(lèi)屬性有foodname foodPrice foodnumb 和一些必要函數(shù) 這個(gè)類(lèi)負(fù)責(zé)封裝食物屬性
* Demo1 是主程序 核心 是HashMap 集合,HashMap<Kfcfood , String > 做購(gòu)物車(chē) 添加食物 和遍歷打印小票
* 用字符輸出流 很簡(jiǎn)潔的寫(xiě)法寫(xiě)入文本
* BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt",true)));//字符緩沖輸出流
*
* */
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
public class Demo1 {
public static void main(String[] args) throws IOException {
Kfcfood k1=new Kfcfood("全家桶",1,(float)(79.9));
Kfcfood k2=new Kfcfood("奧爾良雞腿堡",1,(float)(19.9));
Kfcfood k3=new Kfcfood("熱辣雞腿堡",1,(float)(18.9));
Kfcfood k4=new Kfcfood("帕尼尼早餐套餐",1,(float)(29.9));
Kfcfood k5=new Kfcfood("可樂(lè)",1,(float)(9.9));
Kfcfood k6=new Kfcfood("雞米花",1,(float)(9.9));
Kfcfood k7=new Kfcfood("薯?xiàng)l",1,(float)(8.8));
Kfcfood k8=new Kfcfood("熱辣雞翅",1,(float)(11.9));
Kfcfood k9=new Kfcfood("冰淇淋",1,(float)(9.9));
HashMap<Kfcfood , String > hm= new HashMap<Kfcfood , String >();
System.out.println("**********************************");
System.out.println("*********歡迎光臨肯德基餐廳*************");
System.out.println(" 菜單 ");
System.out.println("1:"+k1.toString());
System.out.println("2:"+k2.toString());
System.out.println("3:"+k3.toString());
System.out.println("4:"+k4.toString());
System.out.println("5:"+k5.toString());
System.out.println("6:"+k6.toString());
System.out.println("7:"+k7.toString());
System.out.println("8:"+k8.toString());
System.out.println("9:"+k9.toString());
boolean z=true ; int count=1;//計(jì)數(shù)器
float total=0;
while(z) {
System.out.println("請(qǐng)點(diǎn)餐 :輸入編號(hào)");
Scanner sc = new Scanner (System.in );
int i = sc.nextInt();
switch (i) {
case 1:
System.out.println(count+k1.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc1= new Scanner (System.in );
int n = sc1.nextInt();
k1.setFnumb(n);//輸入數(shù)量
total=total+k1.getfPrice();//計(jì)算入總價(jià)
hm.put(k1,"數(shù)量:"+String.valueOf( k1.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 2:
System.out.println(count+k2.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc2= new Scanner (System.in );
int n2 = sc2.nextInt();
k2.setFnumb(n2);
total=total+k2.getfPrice();//計(jì)算入總價(jià)
hm.put(k2,"數(shù)量:"+String.valueOf( k2.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 3:
System.out.println(count+k3.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc3= new Scanner (System.in );
int n3 = sc3.nextInt();
k3.setFnumb(n3);
total=total+k3.getfPrice();//計(jì)算入總價(jià)
hm.put(k3,"數(shù)量:"+String.valueOf( k3.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 4:
System.out.println(count+k4.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc4= new Scanner (System.in );
int n4 = sc4.nextInt();
k4.setFnumb(n4);
total=total+k4.getfPrice();//計(jì)算入總價(jià)
hm.put(k4,"數(shù)量:"+String.valueOf( k4.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 5:
System.out.println(count+k5.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc5= new Scanner (System.in );
int n5 = sc5.nextInt();
k5.setFnumb(n5);
total=total+k5.getfPrice();//計(jì)算入總價(jià)
hm.put(k5,"數(shù)量:"+String.valueOf( k5.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 6:
System.out.println(count+k6.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc6= new Scanner (System.in );
int n6 = sc6.nextInt();
k6.setFnumb(n6);
total=total+k6.getfPrice();//計(jì)算入總價(jià)
hm.put(k6,"數(shù)量:"+String.valueOf( k6.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 7:
System.out.println(count+k7.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc7= new Scanner (System.in );
int n7 = sc7.nextInt();
k7.setFnumb(n7);
total=total+k7.getfPrice();//計(jì)算入總價(jià)
hm.put(k7,"數(shù)量:"+String.valueOf( k7.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 8:
System.out.println(count+k8.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc8= new Scanner (System.in );
int n8 = sc8.nextInt();
k8.setFnumb(n8);
total=total+k8.getfPrice();//計(jì)算入總價(jià)
hm.put(k8,"數(shù)量:"+String.valueOf( k8.getFnumb()) );//添加進(jìn)樹(shù)
break;
case 9:
System.out.println(count+k9.getFname());
System.out.println("請(qǐng)輸入數(shù)量:");
Scanner sc9= new Scanner (System.in );
int n9 = sc9.nextInt();
k9.setFnumb(n9);
total=total+k9.getfPrice();//計(jì)算入總價(jià)
hm.put(k9,"數(shù)量:"+String.valueOf( k9.getFnumb()) );//添加進(jìn)樹(shù)
break;
default:System.out.println("請(qǐng)輸入正確的號(hào)碼!");
break;
}
//遍歷樹(shù)
Set<Kfcfood> ks1 = hm.keySet();//遍歷Map
for(Kfcfood s2:ks1) {
System.out.println("("+s2+","+hm.get(s2)+")");
}
System.out.println("1 繼續(xù)點(diǎn)餐 2 重新點(diǎn)餐 3 結(jié)束點(diǎn)餐 ");
Scanner sca= new Scanner (System.in );
int n = sca.nextInt();
switch(n) {
case 1:
count++;
break ;
case 2 :
System.out.println("重新點(diǎn)餐!");
hm.clear();
break;
case 3 :
System.out.println("總價(jià)"+total);
System.out.println("結(jié)束點(diǎn)餐");
z=false;
break;
default:System.out.println("請(qǐng)輸入正確的號(hào)碼!");
break;
}
}
System.out.println("****************************************");
System.out.println("*********歡迎光臨肯德基餐廳*************");
System.out.println(" 您的菜單為! ");
//遍歷樹(shù)
Set<Kfcfood> ks1 = hm.keySet();//遍歷Map
for(Kfcfood s2:ks1) {
System.out.println(" "+s2+", "+hm.get(s2)+" ");
}
System.out.println("總價(jià)"+total);
System.out.println("訂單時(shí)間: "+new Date());
System.err.println(" 歡迎下次光臨!");
System.out.println("**********************************");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt")));//字符緩沖輸出流
bw.write("****************************************");bw.newLine();
bw.write("*********歡迎光臨肯德基餐!*************");bw.newLine();
bw.write(" 您的菜單為! ");bw.newLine();
Set<Kfcfood> ks2 = hm.keySet();//遍歷Map
for(Kfcfood s2:ks2) {
// System.out.println(" "+s2+", "+hm.get(s2)+" ");
bw.write(s2+", "+hm.get(s2));bw.newLine();
}
//System.out.println("總價(jià)"+total);
bw.write("訂單時(shí)間: "+new Date());bw.newLine();
bw.write(" 歡迎下次光臨!");bw.newLine();
bw.write("**********************************");bw.newLine();
bw.flush();
bw.close();
}
}
運(yùn)行結(jié)果:




更多學(xué)習(xí)資料請(qǐng)關(guān)注專(zhuān)題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java點(diǎn)餐小程序之黑心商人
- 用SpringBoot+Vue+uniapp小程序?qū)崿F(xiàn)在線房屋裝修管理系統(tǒng)
- Java基于IDEA實(shí)現(xiàn)qq郵件發(fā)送小程序
- 微信小程序與Java后端接口交互
- 微信小程序微信登錄的實(shí)現(xiàn)方法詳解(JAVA后臺(tái))
- 微信小程序獲取手機(jī)號(hào)的完整實(shí)例(Java后臺(tái)實(shí)現(xiàn))
- java實(shí)現(xiàn)日歷窗口小程序
- Java中生成微信小程序太陽(yáng)碼的實(shí)現(xiàn)方案
- java小程序火鍋店點(diǎn)餐系統(tǒng)
相關(guān)文章
一個(gè)簡(jiǎn)陋的java圖書(shū)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了一個(gè)簡(jiǎn)陋的java圖書(shū)管理系統(tǒng),簡(jiǎn)單的實(shí)現(xiàn)功能測(cè)試,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
springboot web項(xiàng)目打jar或者war包并運(yùn)行的實(shí)現(xiàn)
這篇文章主要介紹了springboot web項(xiàng)目打jar或者war包并運(yùn)行的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
springboot單元測(cè)試兩種方法實(shí)例詳解
這篇文章主要介紹了springboot單元測(cè)試兩種方法實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
關(guān)于nacos無(wú)法正常下線問(wèn)題記錄
這篇文章主要介紹了關(guān)于nacos無(wú)法正常下線問(wèn)題記錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
SpringBoot學(xué)習(xí)之全局異常處理設(shè)置(返回JSON)
本篇文章主要介紹了SpringBoot學(xué)習(xí)之全局異常處理設(shè)置(返回JSON),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
深度解析SpringBoot中@Async引起的循環(huán)依賴(lài)
本文主要介紹了深度解析SpringBoot中@Async引起的循環(huán)依賴(lài),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Spring Boot Admin(監(jiān)控工具)的使用
今天我們將會(huì)講解一個(gè)優(yōu)秀的監(jiān)控工具Spring Boot Admin。 它采用圖形化的界面,讓我們的Spring Boot管理更加簡(jiǎn)單,需要的朋友可以參考下2020-02-02

