java实现KFC点餐小程序
作者:java_YoungOG_KXD 时间:2022-12-11 21:06:51
本文实例为大家分享了java实现KFC点餐系统的具体代码,供大家参考,具体内容如下
package KFC点餐系统;
//food 类
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 + " 价格 [" + fPrice + "]";
}
}
package KFC点餐系统;
/*
* 1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。
* */
/*@author:kxd
* @Date:2018.10.25
*
* 本人写这个小程序,第一创建Kfcfood类属性有foodname foodPrice foodnumb 和一些必要函数 这个类负责封装食物属性
* Demo1 是主程序 核心 是HashMap 集合,HashMap<Kfcfood , String > 做购物车 添加食物 和遍历打印小票
* 用字符输出流 很简洁的写法写入文本
* 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("可乐",1,(float)(9.9));
Kfcfood k6=new Kfcfood("鸡米花",1,(float)(9.9));
Kfcfood k7=new Kfcfood("薯条",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;//计数器
float total=0;
while(z) {
System.out.println("请点餐 :输入编号");
Scanner sc = new Scanner (System.in );
int i = sc.nextInt();
switch (i) {
case 1:
System.out.println(count+k1.getFname());
System.out.println("请输入数量:");
Scanner sc1= new Scanner (System.in );
int n = sc1.nextInt();
k1.setFnumb(n);//输入数量
total=total+k1.getfPrice();//计算入总价
hm.put(k1,"数量:"+String.valueOf( k1.getFnumb()) );//添加进树
break;
case 2:
System.out.println(count+k2.getFname());
System.out.println("请输入数量:");
Scanner sc2= new Scanner (System.in );
int n2 = sc2.nextInt();
k2.setFnumb(n2);
total=total+k2.getfPrice();//计算入总价
hm.put(k2,"数量:"+String.valueOf( k2.getFnumb()) );//添加进树
break;
case 3:
System.out.println(count+k3.getFname());
System.out.println("请输入数量:");
Scanner sc3= new Scanner (System.in );
int n3 = sc3.nextInt();
k3.setFnumb(n3);
total=total+k3.getfPrice();//计算入总价
hm.put(k3,"数量:"+String.valueOf( k3.getFnumb()) );//添加进树
break;
case 4:
System.out.println(count+k4.getFname());
System.out.println("请输入数量:");
Scanner sc4= new Scanner (System.in );
int n4 = sc4.nextInt();
k4.setFnumb(n4);
total=total+k4.getfPrice();//计算入总价
hm.put(k4,"数量:"+String.valueOf( k4.getFnumb()) );//添加进树
break;
case 5:
System.out.println(count+k5.getFname());
System.out.println("请输入数量:");
Scanner sc5= new Scanner (System.in );
int n5 = sc5.nextInt();
k5.setFnumb(n5);
total=total+k5.getfPrice();//计算入总价
hm.put(k5,"数量:"+String.valueOf( k5.getFnumb()) );//添加进树
break;
case 6:
System.out.println(count+k6.getFname());
System.out.println("请输入数量:");
Scanner sc6= new Scanner (System.in );
int n6 = sc6.nextInt();
k6.setFnumb(n6);
total=total+k6.getfPrice();//计算入总价
hm.put(k6,"数量:"+String.valueOf( k6.getFnumb()) );//添加进树
break;
case 7:
System.out.println(count+k7.getFname());
System.out.println("请输入数量:");
Scanner sc7= new Scanner (System.in );
int n7 = sc7.nextInt();
k7.setFnumb(n7);
total=total+k7.getfPrice();//计算入总价
hm.put(k7,"数量:"+String.valueOf( k7.getFnumb()) );//添加进树
break;
case 8:
System.out.println(count+k8.getFname());
System.out.println("请输入数量:");
Scanner sc8= new Scanner (System.in );
int n8 = sc8.nextInt();
k8.setFnumb(n8);
total=total+k8.getfPrice();//计算入总价
hm.put(k8,"数量:"+String.valueOf( k8.getFnumb()) );//添加进树
break;
case 9:
System.out.println(count+k9.getFname());
System.out.println("请输入数量:");
Scanner sc9= new Scanner (System.in );
int n9 = sc9.nextInt();
k9.setFnumb(n9);
total=total+k9.getfPrice();//计算入总价
hm.put(k9,"数量:"+String.valueOf( k9.getFnumb()) );//添加进树
break;
default:System.out.println("请输入正确的号码!");
break;
}
//遍历树
Set<Kfcfood> ks1 = hm.keySet();//遍历Map
for(Kfcfood s2:ks1) {
System.out.println("("+s2+","+hm.get(s2)+")");
}
System.out.println("1 继续点餐 2 重新点餐 3 结束点餐 ");
Scanner sca= new Scanner (System.in );
int n = sca.nextInt();
switch(n) {
case 1:
count++;
break ;
case 2 :
System.out.println("重新点餐!");
hm.clear();
break;
case 3 :
System.out.println("总价"+total);
System.out.println("结束点餐");
z=false;
break;
default:System.out.println("请输入正确的号码!");
break;
}
}
System.out.println("****************************************");
System.out.println("*********欢迎光临肯德基餐厅*************");
System.out.println(" 您的菜单为! ");
//遍历树
Set<Kfcfood> ks1 = hm.keySet();//遍历Map
for(Kfcfood s2:ks1) {
System.out.println(" "+s2+", "+hm.get(s2)+" ");
}
System.out.println("总价"+total);
System.out.println("订单时间: "+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("总价"+total);
bw.write("订单时间: "+new Date());bw.newLine();
bw.write(" 欢迎下次光临!");bw.newLine();
bw.write("**********************************");bw.newLine();
bw.flush();
bw.close();
}
}
运行结果:
更多学习资料请关注专题《管理系统开发》。
来源:https://blog.csdn.net/harvestUachieve/article/details/83422283
标签:java,KFC,点餐系统
0
投稿
猜你喜欢
Android实现网页图片浏览功能
2023-09-05 00:16:09
spring基于注解配置实现事务控制操作
2021-12-07 11:58:24
通过实例讲解springboot整合WebSocket
2023-03-07 07:02:03
全面解读C#编程中的析构函数用法
2021-05-24 00:27:33
Spring Boot中的Properties的使用详解
2021-07-02 07:25:22
基于C#解决库存扣减及订单创建时防止并发死锁的问题
2023-03-16 20:59:53
Java编写实现坦克大战小游戏
2023-11-24 09:15:34
C语言实现贪吃蛇游戏演示
2023-07-03 14:16:43
Java本地缓存的实现代码
2022-02-22 11:21:04
Jenkins+Maven+SVN自动化部署java项目
2021-06-01 11:28:27
Android仿简书搜索框效果的示例代码
2023-06-18 16:02:58
浅谈xml配置spring profiles的几个注意点
2022-07-20 15:20:09
Java实现监控多个线程状态的简单实例
2022-01-25 02:03:38
使用VS2010 C#开发ActiveX控件(下),完整代码打包下载
2022-08-20 18:05:29
java教程之java注解annotation使用方法
2023-11-13 20:18:57
基于sharding-jdbc的使用限制
2023-09-01 12:33:58
Android使用lottie加载json动画的示例代码
2021-06-20 00:47:01
彻底掌握C语言strcpy函数的用法
2023-07-03 07:21:18
Java中二维数组的正确使用方法介绍
2023-11-19 16:14:18
C#使用dynamic类型访问JObject对象
2022-03-01 13:05:28