当前位置:   article > 正文

Kfc点餐系统 小程序_kfc小程序源码

kfc小程序源码

  1. package KFC点餐系统;
  2. //food 类
  3. public class Kfcfood {
  4. private String fname ;
  5. private int fnumb=1;
  6. private float fPrice;
  7. public Kfcfood() {
  8. super();
  9. }
  10. public Kfcfood(String fname, int fnumb, float fPrice) {
  11. super();
  12. this.fname = fname;
  13. this.fnumb = fnumb;
  14. this.fPrice = fPrice;
  15. }
  16. public String getFname() {
  17. return fname;
  18. }
  19. public void setFname(String fname) {
  20. this.fname = fname;
  21. }
  22. public int getFnumb() {
  23. return fnumb;
  24. }
  25. public void setFnumb(int fnumb) {
  26. this.fnumb = fnumb;
  27. }
  28. public float getfPrice() {
  29. return fPrice*fnumb;
  30. }
  31. public void setfPrice(float fPrice) {
  32. this.fPrice = fPrice;
  33. }
  34. @Override
  35. public String toString() {
  36. return fname + " 价格 [" + fPrice + "]";
  37. }
  38. }
  1. package KFC点餐系统;
  2. /*
  3. * 1.正常餐品结算和找零。
  4. 2.基本套餐结算和找零。
  5. 3.使用优惠劵购买餐品结算和找零。
  6. 4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
  7. 5.模拟打印小票的功能(写到文件中)。
  8. * */
  9. /*@author:kxd
  10. * @Date:2018.10.25
  11. *
  12. * 本人写这个小程序,第一创建Kfcfood类属性有foodname foodPrice foodnumb 和一些必要函数 这个类负责封装食物属性
  13. * Demo1 是主程序 核心 是HashMap 集合,HashMap<Kfcfood , String > 做购物车 添加食物 和遍历打印小票
  14. * 用字符输出流 很简洁的写法写入文本
  15. * BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt",true)));//字符缓冲输出流
  16. *
  17. * */
  18. import java.io.BufferedWriter;
  19. import java.io.FileNotFoundException;
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22. import java.io.OutputStreamWriter;
  23. import java.util.Date;
  24. import java.util.HashMap;
  25. import java.util.Scanner;
  26. import java.util.Set;
  27. public class Demo1 {
  28. public static void main(String[] args) throws IOException {
  29. Kfcfood k1=new Kfcfood("全家桶",1,(float)(79.9));
  30. Kfcfood k2=new Kfcfood("奥尔良鸡腿堡",1,(float)(19.9));
  31. Kfcfood k3=new Kfcfood("热辣鸡腿堡",1,(float)(18.9));
  32. Kfcfood k4=new Kfcfood("帕尼尼早餐套餐",1,(float)(29.9));
  33. Kfcfood k5=new Kfcfood("可乐",1,(float)(9.9));
  34. Kfcfood k6=new Kfcfood("鸡米花",1,(float)(9.9));
  35. Kfcfood k7=new Kfcfood("薯条",1,(float)(8.8));
  36. Kfcfood k8=new Kfcfood("热辣鸡翅",1,(float)(11.9));
  37. Kfcfood k9=new Kfcfood("冰淇淋",1,(float)(9.9));
  38. HashMap<Kfcfood , String > hm= new HashMap<Kfcfood , String >();
  39. System.out.println("**********************************");
  40. System.out.println("*********欢迎光临肯德基餐厅*************");
  41. System.out.println(" 菜单 ");
  42. System.out.println("1:"+k1.toString());
  43. System.out.println("2:"+k2.toString());
  44. System.out.println("3:"+k3.toString());
  45. System.out.println("4:"+k4.toString());
  46. System.out.println("5:"+k5.toString());
  47. System.out.println("6:"+k6.toString());
  48. System.out.println("7:"+k7.toString());
  49. System.out.println("8:"+k8.toString());
  50. System.out.println("9:"+k9.toString());
  51. boolean z=true ; int count=1;//计数器
  52. float total=0;
  53. while(z) {
  54. System.out.println("请点餐 :输入编号");
  55. Scanner sc = new Scanner (System.in );
  56. int i = sc.nextInt();
  57. switch (i) {
  58. case 1:
  59. System.out.println(count+k1.getFname());
  60. System.out.println("请输入数量:");
  61. Scanner sc1= new Scanner (System.in );
  62. int n = sc1.nextInt();
  63. k1.setFnumb(n);//输入数量
  64. total=total+k1.getfPrice();//计算入总价
  65. hm.put(k1,"数量:"+String.valueOf( k1.getFnumb()) );//添加进树
  66. break;
  67. case 2:
  68. System.out.println(count+k2.getFname());
  69. System.out.println("请输入数量:");
  70. Scanner sc2= new Scanner (System.in );
  71. int n2 = sc2.nextInt();
  72. k2.setFnumb(n2);
  73. total=total+k2.getfPrice();//计算入总价
  74. hm.put(k2,"数量:"+String.valueOf( k2.getFnumb()) );//添加进树
  75. break;
  76. case 3:
  77. System.out.println(count+k3.getFname());
  78. System.out.println("请输入数量:");
  79. Scanner sc3= new Scanner (System.in );
  80. int n3 = sc3.nextInt();
  81. k3.setFnumb(n3);
  82. total=total+k3.getfPrice();//计算入总价
  83. hm.put(k3,"数量:"+String.valueOf( k3.getFnumb()) );//添加进树
  84. break;
  85. case 4:
  86. System.out.println(count+k4.getFname());
  87. System.out.println("请输入数量:");
  88. Scanner sc4= new Scanner (System.in );
  89. int n4 = sc4.nextInt();
  90. k4.setFnumb(n4);
  91. total=total+k4.getfPrice();//计算入总价
  92. hm.put(k4,"数量:"+String.valueOf( k4.getFnumb()) );//添加进树
  93. break;
  94. case 5:
  95. System.out.println(count+k5.getFname());
  96. System.out.println("请输入数量:");
  97. Scanner sc5= new Scanner (System.in );
  98. int n5 = sc5.nextInt();
  99. k5.setFnumb(n5);
  100. total=total+k5.getfPrice();//计算入总价
  101. hm.put(k5,"数量:"+String.valueOf( k5.getFnumb()) );//添加进树
  102. break;
  103. case 6:
  104. System.out.println(count+k6.getFname());
  105. System.out.println("请输入数量:");
  106. Scanner sc6= new Scanner (System.in );
  107. int n6 = sc6.nextInt();
  108. k6.setFnumb(n6);
  109. total=total+k6.getfPrice();//计算入总价
  110. hm.put(k6,"数量:"+String.valueOf( k6.getFnumb()) );//添加进树
  111. break;
  112. case 7:
  113. System.out.println(count+k7.getFname());
  114. System.out.println("请输入数量:");
  115. Scanner sc7= new Scanner (System.in );
  116. int n7 = sc7.nextInt();
  117. k7.setFnumb(n7);
  118. total=total+k7.getfPrice();//计算入总价
  119. hm.put(k7,"数量:"+String.valueOf( k7.getFnumb()) );//添加进树
  120. break;
  121. case 8:
  122. System.out.println(count+k8.getFname());
  123. System.out.println("请输入数量:");
  124. Scanner sc8= new Scanner (System.in );
  125. int n8 = sc8.nextInt();
  126. k8.setFnumb(n8);
  127. total=total+k8.getfPrice();//计算入总价
  128. hm.put(k8,"数量:"+String.valueOf( k8.getFnumb()) );//添加进树
  129. break;
  130. case 9:
  131. System.out.println(count+k9.getFname());
  132. System.out.println("请输入数量:");
  133. Scanner sc9= new Scanner (System.in );
  134. int n9 = sc9.nextInt();
  135. k9.setFnumb(n9);
  136. total=total+k9.getfPrice();//计算入总价
  137. hm.put(k9,"数量:"+String.valueOf( k9.getFnumb()) );//添加进树
  138. break;
  139. default:System.out.println("请输入正确的号码!");
  140. break;
  141. }
  142. //遍历树
  143. Set<Kfcfood> ks1 = hm.keySet();//遍历Map
  144. for(Kfcfood s2:ks1) {
  145. System.out.println("("+s2+","+hm.get(s2)+")");
  146. }
  147. System.out.println("1 继续点餐 2 重新点餐 3 结束点餐 ");
  148. Scanner sca= new Scanner (System.in );
  149. int n = sca.nextInt();
  150. switch(n) {
  151. case 1:
  152. count++;
  153. break ;
  154. case 2 :
  155. System.out.println("重新点餐!");
  156. hm.clear();
  157. break;
  158. case 3 :
  159. System.out.println("总价"+total);
  160. System.out.println("结束点餐");
  161. z=false;
  162. break;
  163. default:System.out.println("请输入正确的号码!");
  164. break;
  165. }
  166. }
  167. System.out.println("****************************************");
  168. System.out.println("*********欢迎光临肯德基餐厅*************");
  169. System.out.println(" 您的菜单为! ");
  170. //遍历树
  171. Set<Kfcfood> ks1 = hm.keySet();//遍历Map
  172. for(Kfcfood s2:ks1) {
  173. System.out.println(" "+s2+", "+hm.get(s2)+" ");
  174. }
  175. System.out.println("总价"+total);
  176. System.out.println("订单时间: "+new Date());
  177. System.err.println(" 欢迎下次光临!");
  178. System.out.println("**********************************");
  179. BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt")));//字符缓冲输出流
  180. bw.write("****************************************");bw.newLine();
  181. bw.write("*********欢迎光临肯德基餐!*************");bw.newLine();
  182. bw.write(" 您的菜单为! ");bw.newLine();
  183. Set<Kfcfood> ks2 = hm.keySet();//遍历Map
  184. for(Kfcfood s2:ks2) {
  185. // System.out.println(" "+s2+", "+hm.get(s2)+" ");
  186. bw.write(s2+", "+hm.get(s2));bw.newLine();
  187. }
  188. //System.out.println("总价"+total);
  189. bw.write("订单时间: "+new Date());bw.newLine();
  190. bw.write(" 欢迎下次光临!");bw.newLine();
  191. bw.write("**********************************");bw.newLine();
  192. bw.flush();
  193. bw.close();
  194. }
  195. }

运行结果:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/80676
推荐阅读
相关标签
  

闽ICP备14008679号