亲宝软件园·资讯

展开

java外卖订餐系统 java实现外卖订餐系统

小苏(º﹃º ) 人气:1

一、使用技术

javaSE

二、实现功能

外卖订餐系统

具体要求如下:

使用选择结构,循环结构,数组的知识实现一个外卖订餐系统

三、运行效果图

1.订餐功能

2.查看餐袋

3.签收订单

4.删除订单

5.点赞

6.退出

分析图片信息,可以看出我们需要创建一个菜单类,查看餐带类和点赞菜单类

1.首先我们创建一个菜单类,用来定义菜单的属性,使用到封装,构造方法,和toString方法。

public class Food {//菜单

 @Override
 public String toString() {
 return "Food{" +
 "num=" + num +
 ", name='" + name + '\'' +
 ", price=" + price +
 '}';
 }

 private int num;
 private String name;
 private double price;

 public Food() {
 }

 public Food(int num, String name, double price) {
 this.num = num;
 this.name = name;
 this.price = price;
 }

 public int getNum() {
 return num;
 }

 public void setNum(int num) {
 this.num = num;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public double getPrice() {
 return price;
 }

 public void setPrice(double price) {
 this.price = price;
 }
}

2.其次,我们在创建一个查看餐袋类

public class SeeFood {//查看餐带
 private int num;//序号
 private String name;//订餐人
 //private String information;//信息
 private String food;//菜品
 private int num1;//份数
 private int date;//送餐日期
 private String address;//送餐地址
 private double money;//金额
 private String state;//订单状态

 @Override
 public String toString() {
 return "SeeFood{" +
 "num=" + num +
 ", name='" + name + '\'' +
 ", food='" + food + '\'' +
 ", num1=" + num1 +
 ", date='" + date + '\'' +
 ", address='" + address + '\'' +
 ", money=" + money +
 ", state='" + state + '\'' +
 '}';
 }

 public int getNum() {
 return num;
 }

 public void setNum(int num) {
 this.num = num;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public String getFood() {
 return food;
 }

 public void setFood(String food) {
 this.food = food;
 }

 public int getNum1() {
 return num1;
 }

 public void setNum1(int num1) {
 this.num1 = num1;
 }

 public int getDate() {
 return date;
 }

 public void setDate(int date) {
 this.date = date;
 }

 public String getAddress() {
 return address;
 }

 public void setAddress(String address) {
 this.address = address;
 }

 public double getMoney() {
 return money;
 }

 public void setMoney(double money) {
 this.money = money;
 }

 public String getState() {
 return state;
 }

 public void setState(String state) {
 this.state = state;
 }

 public SeeFood() {
 }

 public SeeFood(int num, String name, String food,
 int num1, int date, String address,
 double money, String state) {
 this.num = num;
 this.name = name;
 this.food = food;
 this.num1 = num1;
 this.date = date;
 this.address = address;
 this.money = money;
 this.state = state;
 }
}

3.再创建一个点赞菜单类

public class FabulousFood {//点赞菜单
 private int num;//序号
 private String name;
 private double price;
 private int numfabulous;//点赞序号
 private String fabulous;

 @Override
 public String toString() {
 return "FabulousFood{" +
 "num=" + num +
 ", name='" + name + '\'' +
 ", price=" + price +" "+
 numfabulous +
 fabulous + '\'' +
 '}';
 }

 public FabulousFood() {
 }

 public FabulousFood(int num, String name, double price, int numfabulous, String fabulous) {
 this.num = num;
 this.name = name;
 this.price = price;
 this.numfabulous = numfabulous;
 this.fabulous = fabulous;
 }

 public int getNum() {
 return num;
 }

 public void setNum(int num) {
 this.num = num;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public double getPrice() {
 return price;
 }

 public void setPrice(double price) {
 this.price = price;
 }

 public int getNumfabulous() {
 return numfabulous;
 }

 public void setNumfabulous(int numfabulous) {
 this.numfabulous = numfabulous;
 }

 public String getFabulous() {
 return fabulous;
 }

 public void setFabulous(String fabulous) {
 this.fabulous = fabulous;
 }
}

4.创建点餐系统实现其功能,每个功能都使用方法来实现

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class OrderFood {//点餐
 static Scanner sc=new Scanner(System.in);
 static int date;//送餐时间
 static int number=0;//餐带序号
 public static void main(String[] args) {
 ArrayList<Food> list = new ArrayList<>();
 list.add(new Food(1, "红烧茄子", 24));
 list.add(new Food(2, "红烧排骨", 36));
 list.add(new Food(3, "鱼香肉丝", 32));
 ArrayList<FabulousFood> list2 = new ArrayList<>();
 list2.add(new FabulousFood(1, "红烧茄子", 24,0,"赞"));
 list2.add(new FabulousFood(2, "红烧排骨", 36,0,"赞"));
 list2.add(new FabulousFood(3, "鱼香肉丝", 32,0,"赞"));
 ArrayList<SeeFood> list1 = new ArrayList<>();
 System.out.println(" 欢迎使用“外卖点餐系统”");
 System.out.println("*******************************");
 orderFood(list,list1,list2);
 }

 public static void orderFood(ArrayList<Food> list1,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//点餐系统界面
 // System.out.println(" 欢迎使用“外卖点餐系统”");
 //System.out.println("*******************************");
 System.out.println("1、我要点餐");
 System.out.println("2、查看餐带");
 System.out.println("3、签收订单");
 System.out.println("4、删除订单");
 System.out.println("5、我要点赞");
 System.out.println("6、退出系统");
 System.out.println("*******************************");
 System.out.println("请选择:");
 String num=sc.next();
 if (num.equals("1")){
 orderingFood(list1,list2,list3);
 }else if (num.equals("2")){
 seeFood(list1, list2,list3);
 }else if (num.equals("3")){
 signFor(list1, list2,list3);
 }else if (num.equals("4")){
 deletFood(list1,list2,list3);
 }else if (num.equals("5")){
 fabulousFood(list1,list2,list3);
 }else if (num.equals("6")){
 System.out.println("谢谢使用,欢迎下次光临!");
 return;
 }else {
 System.out.println("输出错误,请重新输入!");
 orderFood(list1,list2,list3);
 }
 }

 public static void fabulousFood(ArrayList<Food> list,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//点赞
 System.out.println("******我要点赞******");
 System.out.println("序号 菜名 单价");
 Iterator<FabulousFood> it = list3.iterator();
 while (it.hasNext()){
 System.out.println(it.next());
 }
 System.out.println("请选择您要点赞的菜品序号:");
 int num=sc.nextInt();
 for (int i = 0; i <list.size() ; i++) {
 if (num==list.get(i).getNum()){
 list3.get(i).setNumfabulous((list3.get(i).getNumfabulous()+1));
 }
 }
 System.out.println("点赞成功!");
 System.out.println("输入0返回");
 int b=sc.nextInt();
 if (b==0){
 orderFood(list,list2,list3);
 }
 }

 public static void deletFood(ArrayList<Food> list,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//删除订单
 System.out.println("请输入要删除的订单序号");
 int a=sc.nextInt();
 for (int i = 0; i <list2.size() ; i++) {
 if (a==list2.get(i).getNum()){
 list2.remove(list2.get(i));

 }
 }
 System.out.println("删除订单成功!");
 System.out.println("输入0返回");
 int b=sc.nextInt();
 if (b==0){
 orderFood(list,list2,list3);
 }
 }

 public static void signFor(ArrayList<Food> list,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//签收订单
 System.out.println("请输入要签收的的订单序号:");
 int sign=sc.nextInt();
 for (int i = 0; i <list.size() ; i++) {
 if (sign==(list.get(i).getNum())){
 list2.get(i).setState("已签收");
 }
 }
 System.out.println("订单签收成功!");
 System.out.println("输入0返回");
 int a=sc.nextInt();
 if (a==0){
 orderFood(list,list2,list3);
 }
 }

 public static void seeFood(ArrayList<Food> list,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//查看餐带
 System.out.println("******查看餐带******");
 System.out.println(" 序号 订餐人 餐品信息 送餐日期 " +
 " 送餐地址 总金额 订单状态");
 Iterator<SeeFood> it = list2.iterator();
 while (it.hasNext()){
 System.out.println(it.next());
 }
 System.out.println("输入0返回");
 int a=sc.nextInt();
 if (a==0){
 orderFood(list,list2,list3);
 }


 }
 public static void orderingFood(ArrayList<Food> list1,ArrayList<SeeFood> list2,ArrayList<FabulousFood> list3){//订餐
 System.out.println("我要订餐");
 System.out.println("请输入订餐人的姓名:");
 String name=sc.next();
 System.out.println("序号 菜名 单价");
 Iterator<Food> it = list1.iterator();
 while (it.hasNext()){
 System.out.println(it.next());
 }
 System.out.println("请输入您要点的菜品编号");
 int num=sc.nextInt();
 System.out.println("请选择您需要的份数");
 int num1=sc.nextInt();
 foodDelilvery();
 int num3=date;//送餐时间
 System.out.println("请输入送餐地址");
 String address=sc.next();
 System.out.println("订餐成功!");
 number++;//餐带序号
 System.out.print("您订的是:");
 String food=list1.get(num-1).getName();//菜品
 System.out.println(food+" "+num1+"份");
 System.out.println("送餐时间:"+date+"点");
 double money=list1.get(num-1).getPrice()*num1;//餐费
 System.out.println("餐费:"+money
 +"元,送餐费6.0元,总计:"+(money+6)+"元");
 //姓名,份数,时间,地址,菜品,餐费
 list2.add(new SeeFood(number,name,food,num1,num3,address,(money+6),"已预定"));
 System.out.println("输入0返回:");
 String input=sc.next();
 if (input.equals("0")){
 orderFood(list1,list2,list3);
 }else {
 System.out.println("欢迎下次光临");
 }

 }

 static public void foodDelilvery(){//送餐时间
 System.out.println("请输入送餐的时间(送餐时间是10点至20点间整点送餐):");
 int num2=sc.nextInt();
 date=num2;
 if (num2<10||num2>20){
 System.out.println("不在送餐时间!");
 foodDelilvery();
 }

 }
}

1.点餐功能

2.查看餐带

3.签收订单

4.删除订单

5.我要点赞

6.退出系统

加载全部内容

相关教程
猜你喜欢
用户评论