JAVA吃货联盟项目。

1基础通过数组、选择结构、循环等实 现吃货联盟订餐系统。

1、我要订餐;

2、查看餐袋;

3、签收订单;

4、删除订单;

5、我要点赞;

6、退出系统;

public class Doy001 {
    public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                String[] names = new String[4];
                String[] dishMegs = new String[4];
                int[] times = new int[4];
                String[] addresses = new String[4];
                int[] states = new int[4];
                double[] sumPrices = new double[4];

                names[0] = "wuli丫头";
                dishMegs[0] = "汉堡2份";
                times[0] = 12;
                addresses[0] = "青年路";
                sumPrices[0] = 76.0;
                states[0] = 1;
                // 第二条订单信息
                names[1] = "wuli小仙女";
                dishMegs[1] = "脆皮鸡2份";
                times[1] = 18;
                addresses[1] = "石佛营东里";
                sumPrices[1] = 45.0;
                states[1] = 0;
                // 菜品信息
                String[] dishNames = { "汉堡", "脆皮鸡", "柠檬水" };
                double[] prices = new double[] { 38.0, 20.0, 10.0 };
                int[] praiseNums = new int[3];
                int num = -1;
                boolean flag = false;
                System.out.println("欢迎使用“吃货联盟订餐系统”");
                // 进入循环
                do {
                    // 菜单
                    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.print("请选择:");
                    int choose = input.nextInt();// 输入编号
                    switch (choose) {
                    case 1:
                        System.out.println("****我要订餐****");
                        boolean isAdd = false;
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] == null) {
                                isAdd = true;
                                System.out.print("请输入订餐人姓名:");
                                String name = input.next();
                                // 菜品信息
                                System.out.println("序号" + "\t" + "菜名" + "\t" + "单价");
                                for (int j = 0; j < dishNames.length; j++) {
                                    String price = prices[j] + "元";
                                    String praiseNum = (praiseNums[j] > 0) ? praiseNums[j]
                                            + "赞"
                                            : "0";
                                    System.out.println((j + 1) + "\t" + dishNames[j]
                                            + " \t" + price);
                                }
                                // 点菜
                                System.out.print("请您选择要点的菜品编号:");
                                int chooseDish = input.nextInt();
                                System.out.print("请选择您需要的份数:");
                                int number = input.nextInt();
                                String dishMeg = dishNames[chooseDish - 1] + " "
                                        + number + "份";
                                double sumPrice = prices[chooseDish - 1] * number;
                                double deliCharge = (sumPrice >= 50) ? 0 : 5;// 满50免送餐费
                                System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
                                int time = input.nextInt();
                                while (time < 10 || time > 20) {
                                    System.out.print("您输入的时间有误,请输入10~20间的整数!");
                                    time = input.nextInt();
                                }
                                // 订单信息
                                System.out.print("请输入送餐地址:");
                                String address = input.next();
                                System.out.println("订餐成功!");
                                System.out.println("您订的是:" + dishMeg);
                                System.out.println("送餐时间是:" + time + "点");
                                System.out.println("餐费" + sumPrice + "元,送餐费"
                                        + deliCharge + "元,总计:"
                                        + (sumPrice + deliCharge) + "元");
                                names[i] = name;
                                dishMegs[i] = dishMeg;
                                times[i] = time;
                                addresses[i] = address;
                                sumPrices[i] = sumPrice + deliCharge;
                                break;
                            }
                        }
                        if (!isAdd) {
                            System.out.println("对不起,您的餐袋已满!");
                        }
                        break;
                    case 2:// 查看餐袋
                        System.out.println("****查看餐袋****");
                        System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期"
                                + "\t送餐地址\t\t总金额\t订单状态");
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null) {
                                String state = (states[i] == 0) ? "已预订" : "已完成";
                                String date = times[i] + "日";
                                String sumPrice = sumPrices[i] + "元";
                                System.out.println((i + 1) + "\t" + names[i] + "\t"
                                        + dishMegs[i] + "\t" + date + "\t"
                                        + addresses[i] + "\t" + sumPrice + " \t"
                                        + state);
                            }
                        }
                        break;
                    case 3:// 签收订单
                        System.out.println("****签收订单****");
                        boolean isSignFind = false;// 找到要签收的订单
                        System.out.print("请选择要签收的订单序号:");
                        int choose1 = input.nextInt();
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null && states[i] == 0 && choose1 == i + 1) {
                                states[i] = 1;
                                System.out.println("订单签收成功!");
                                isSignFind = true;
                            } else if (names[i] != null && states[i] == 1
                                    && choose1 == i + 1) {
                                System.out.println("您选择的订单已完成签收,不能再次签收!");
                                isSignFind = true;
                            }
                        }
                        if (!isSignFind) {
                            System.out.println("您选择的订单不存在!");
                        }
                        break;
                    case 4:// 删除订单
                        System.out.println("****签收订单****");
                        boolean isdelFind = false;// 是否删除找到的订单
                        System.out.print("请输入要删除的订单序号:");
                        int choose2 = input.nextInt();
                        for (int i = 0; i < names.length; i++) {
                            if (names[i] != null && states[i] == 1 && choose2 == i + 1) {
                                isdelFind = true;// 已找到订单
                                // 删除操作,删除后的元素依次后移
                                for (int j = choose2 - 1; j < names.length - 1; j++) {
                                    names[j] = names[j + 1];
                                    dishMegs[j] = dishMegs[j + 1];
                                    times[j] = times[j + 1];
                                    addresses[j] = addresses[j + 1];
                                    states[j] = states[j + 1];
                                    sumPrices[j] = sumPrices[j + 1];
                                }
                                // 最后一位清空
                                int endindex = names.length - 1;
                                names[endindex] = null;
                                dishMegs[endindex] = null;
                                times[endindex] = 0;
                                addresses[endindex] = null;
                                states[endindex] = 0;
                                sumPrices[endindex] = 0;
                                System.out.println("删除订单成功!");
                                break;
                            } else if (names[i] != null && states[i] == 0
                                    && choose2 == i + 1) {
                                System.out.println("您选择的订单未签收,不能删除!");
                                isdelFind = true;// 已找到订单
                            }
                        }
                        if (!isdelFind) {
                            System.out.println("您要删除的订单不存在!");
                        }

                        break;
                    case 5:// 我要点赞
                        System.out.println("****我要点赞****");
                        // 展示菜品信息
                        System.out.println("序号" + "\t" + "菜名" + "\t" + "单价");
                        for (int i = 0; i < dishNames.length; i++) {
                            String price = prices[i] + "元";
                            String praiseNum = (praiseNums[i] > 0) ? praiseNums[i]
                                    + "赞" : "0";
                            System.out.println((i + 1) + "\t" + dishNames[i] + "\t"
                                    + price + "\t" + praiseNum);
                        }
                        System.out.print("请选择您要点赞的菜品序号:");
                        int choose3 = input.nextInt();
                        praiseNums[choose3 - 1]++;
                        System.out.println("点赞成功!");
                        break;
                    case 6:// 退出系统
                        flag = true;
                        break;
                    default:
                        // 退出系统
                        flag = true;
                        break;
                    }
                    if (!flag) {
                        System.out.print("输入0返回!");
                        num = input.nextInt();
                    } else {
                        break;
                    }
                } while (num == 0);
                System.out.println("谢谢使用。欢迎下次光临!");

    }

}
时间: 2024-10-09 22:34:46

JAVA吃货联盟项目。的相关文章

吃货联盟项目

public class ddddd { String []name =new String[4];//保存订单人姓名 String []dishMegs =new String[4];//保存所选信息,包括菜品名及份数 String []time =new String[4];//保存送餐时间 String[]address =new String[4];//保存送餐地址 int[]states =new int[4];//保存订单状态:0表预订.1表示完成 double []sumPrice

房上的猫:吃货联盟项目

一.首先先定义部分成员变量: String[] name = new String[4];// 订餐人 String[] greens = new String[4];// 储存菜品名称 String[] green = { "红烧带鱼", "鱼香肉丝", "时令鲜蔬" };// 菜品 int[] num = new int[4];// 份数 int[] time = new int[4];// 时间 String[] site = new St

小项目,吃货联盟,java初级小项目,源代码

1:项目的实现效果.功能如图所示. 2:项目的源代码如下: 1 import java.util.Scanner; 2 3 /** 4 * 吃货联盟订餐管理系统 5 * 6 */ 7 public class OrderingMsg { 8 public static void main(String[] args) { 9 // 数据主体:一组订单信息 10 String[] names = new String[4]; // 订餐人名称 11 String[] dishMegs = new

第一个项目--------------吃货联盟订餐系统

吃货联盟订餐系统 运行效果如图所示: 1.系统界面 2..功能一 3.查看餐袋 4.签收订单 6.我要点赞 1 package cn.zt; 2 3 import java.util.Scanner; 4 import java.util.jar.Attributes.Name; 5 6 public class OrderingMgr { 7 8 /** 9 * @param args 10 */ 11 public static void main(String[] args) { 12 /

案例&gt;&gt;&gt;吃货联盟订餐

import java.util.Scanner; public class VersionAlliance { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] names = new String[4]; // 保存订餐人姓名 String[] dishMegs = new String[4]; // 保存菜名和分数的所选信息 String[] addresses

吃货联盟订餐系统

实现菜单切换: System.out.println("欢迎使用吃货联盟订单系统"); Scanner input = new Scanner(System.in); int num=-1//用户输入0返回主菜单,否则退出系统; bolean isExit=false//标志用户是否退出系统; do{ //显示菜单 System.out.println("********************************************"); System.o

吃货联盟点餐系统

package cn.c; public class OrderingMgr { /** * @param args */ public static void main(String[] args) { OrderingUtil oUtil=new OrderingUtil(); oUtil.startMenu(); } } package cn.c; /** *订单类 */public class OrderingSet { //数组主体:一组订单信息 String[] names=new

吃货联盟订餐系统---添加注释

package com.shuzu; import java.util.Scanner; public class Chihuolianmeng_3 { //吃货订餐联盟---老师版 public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("欢迎使用"吃货联盟订餐系统""); String choose = ""

重写吃货联盟

需求:根据所学面的向对象以及集合知识,重写吃货联盟 1 /** 2 * @author Administrator 3 * 菜单类 4 */ 5 public class Mune { 6 private int num;//菜单序号 7 private String muneNmae;//菜品名 8 private double price;//菜品单价 9 private int Zan;//点赞数 10 public Mune(int num, String muneNmae, doubl