该项目利用Java基础(数据类型、数据、循环等Java基础知识),非常推荐给新手进行操作。
package com.hubstc.order;
import java.util.Scanner;
public class OrderFoodSys {
public static void main(String[] args) {
// TODO Auto-generated method stub
// 各数组主体通过下标进行关联
// 定义数据主体:菜品
String[] dishNames = { "红烧带鱼", "鱼香肉丝", "时令蔬菜" }; // 菜品名称
double[] prices = { 38.0, 20.0, 10.0 }; // 单价
int[] praiseNums = new int[3]; // 点赞数
// 初始化2个订单信息
// 定义数据主体:订单-订餐人 餐品信息 送餐时间 送餐地址 总金额 订单状态
String[] names = new String[4];
String[] dishMsg = new String[4]; // 菜品名称+订份数
int[] times = new int[4];
String[] address = new String[4];
double[] sumPrices = new double[4];
int[] states = new int[4]; // 0:已预订 1:已完成
names[0] = "张三";
dishMsg[0] = "红烧带鱼 2份";
times[0] = 10;
address[0] = "知春路223号";
sumPrices[0] = 76; // 餐费>50元免配送费,否则配送费6元
states[0] = 1;
names[1] = "李四";
dishMsg[1] = "鱼香肉丝 1份";
times[1] = 14;
address[1] = "江汉路223号";
sumPrices[1] = 26; // 餐费>50元免配送费,否则配送费6元
states[1] = 0;
// 搭建项目整体流程框架
Scanner sc = new Scanner(System.in);
int num = -1; // 用户输入0返回时的输入数字,当num = 0时重复显示菜单
System.out.println("欢迎使用“吃货联盟订餐系统”");
// 记录用户是否退出系统的状态:退出:true 不退出:false
boolean flag = false;
do {
System.out.println("****************************************");
System.out.println("1:订餐 2:查看餐袋 3:签收订单 4:删除订单 5:点赞 6:退出");
System.out.println("****************************************");
System.out.println("请选择:");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("\n****************订餐*****************");
/*
* 订餐功能实现代码 功能实现: 订餐前判断订单(boolean变量)是否已满,如果已满则不能订餐,否则就可以订餐
*/
boolean isAdd = false;
for (int i = 0; i < names.length; i++)