文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

如何使用Java实现简单点餐系统

2023-06-29 00:42

关注

小编给大家分享一下如何使用Java实现简单点餐系统,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

程序控制分析:

欢迎页循环:do-while
2、Scanner 控制输入
3、选择页循环:switch-case

要求:

订单信息:String 二维数组
序号、姓名、餐品名称、份数、价格、总价、地址、时间(10-20)、状态(已预定、已完成)、热度(int型)

签收订单:改变订单状态,已预定可以签收,如果已经完成则不能再次签收。

删除订单:不能删除未完成订单,序号要随之改变。

我要点赞:对相应的餐品点赞,并展示。

package Practice;import java.util.Scanner;public class Obj {    public static void main(String[] args) {        Scanner sc=new Scanner(System.in);        String dishes[]={"红烧肉","烧熊掌","清蒸鱼","白斩鸡","烤乳鸽"};        int price[]={58,88,45,56,44};        int honors[]={50,100,20,12,44};        int hot[]={5,4,3,2,0};        String orders[][]=new String[1024][];        int chose=0;        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.println("请选择:");            chose=sc.nextInt();//订餐流程-------------------------------------------------------------------------------------            switch (chose) {                case 1:                    System.out.println("***我要订餐***");                    System.out.println("请输入订餐人姓名:");                    String name=sc.next();                    System.out.println("序号     菜品    单价   热度");                    for (int i = 0; i < dishes.length; i++) {                        System.out.println(i+1+"\t\t"+dishes[i]+"\t"+price[i]+"元\t"+"\t"+hot[i]);                    }                    int dishNum=0;                    do{                        System.out.println("菜品编号");                        dishNum=sc.nextInt();                        if ((dishNum<1||dishNum>dishes.length)){                            System.out.println("对不起,输入有误,请重新输入!");                        }                    }while (dishNum<1||dishNum>dishes.length);                    int pcs=0;                    do {                        System.out.println("份数");                        pcs=sc.nextInt();                        if (pcs<1){                            System.out.println("对不起,输入有误,请重新输入!");                        }                    }while (pcs<1);                    int time;                    do {                        System.out.println("送餐时间");                        time=sc.nextInt();                        if (time<10||time>22){                            System.out.println("对不起,输入有误,请重新输入!");                        }                    }while (time<10||time>22);                    System.out.println("地址");                    String addres=sc.next();                    System.out.println("success!");                    System.out.println(                            "您定的商品信息是:" +dishes[dishNum]+ "\t" +dishNum+"份");                    System.out.println("送餐时间为"+time);                    double cost=price[dishNum-1]*pcs;                    double sent=cost>50?0:6;                    double total=cost+sent;                    System.out.println("餐费共计"+total+" 其中快递费"+sent+"元");                    for (int i = 0; i < orders.length; i++) {                        if (orders[i]==null){                            orders[i]=new String[3];                            orders[i][0]=name+"\t"+dishes[dishNum-1]+"\t"                                    +pcs+"份\t"+time+"\t"+addres+"\t"+cost+"元";  //orders第一存储 菜品信息                            orders[i][1]="已预定";                      //orders第二存储 订单信息                            break;                        }                    }                    break;//查看餐袋------------------------------------------------------------------------------                case 2:                    System.out.println("***查看餐袋***");                    System.out.println("序号\t订餐人  餐品信息 时间 地址 总金额    订单状态");                    for (int i = 0; i < orders.length; i++) {                        if (orders[i]!=null){                            System.out.println(i+1+"\t"+orders[i][0]+"\t\t"+orders[i][1]);                        }else{                            break;                        }                    }                    break;//订单签收----------------------------------------------------------------------------                case 3:                    System.out.println("***签收订单***");                    int num;                    int end=0;                    System.out.println("序号\t订餐人  餐品信息 时间 地址 总金额    订单状态");                    for (int i = 0; i < orders.length; i++) {                        if (orders[i]!=null){                            System.out.println(i+1+"\t"+orders[i][0]+"\t\t"+orders[i][1]);                        }else{                            break;                        }                    }                    do {                        System.out.println("请输入要签收订单序号:");                        for (int i = 0; i < orders.length; i++) {                            if (orders[i]==null){                                end=i+1;                                break;                            }                        }                        num=sc.nextInt();                        if (num<0||num>end){                            System.out.println("输入有误");                        }else if ("已预定".equals(orders[num-1][1])){                            orders[num-1][1]="已完成";                            System.out.println("订单已完成");                            break;                        }else{                            System.out.println("订单已签收,不能重复签收");                            break;                        }                    }while (num<1||num>end||"已预定".equals(orders[num-1][1]));                    break;//删除订单------------------------------------------------------------------------                case 4:                    System.out.println("***删除订单***");                    int n=0;   //输入数字                    int e=0;  // 订单的最大数量                    System.out.println("序号\t订餐人 \t餐品信息 \t送餐时间 \t地址 \t总金额 \t状态");                    for (int i = 0; i < orders.length; i++) {                        if (orders[i]!=null){                            System.out.print(i+1+"\t"+orders[i][0]+"\t"+orders[i][1]+"\t");                            System.out.println("\t  "+orders[i][1]);                        }else{                            break;                        }                    }                    do {                        for (int i = 0; i < orders.length; i++) {        //确定订单的最大数量                            if (orders[i]==null){                                e=i;                                break;                            }                        }                        System.out.println("要删除的订单编号:");                        n=sc.nextInt();                    if (n<1||n>e){                        System.out.println("err");                    }else if ( ! "已完成".equals(orders[n-1][1])){                        System.out.println("订单未完成,不能删除");                        break;                    }else{                        boolean isDelete=false;                        for (int i = n-1; i < orders.length; i++) {                            if (i==orders.length-1){                                orders[i]=null;                                isDelete=true;          //                            }else{                                orders[i]=orders[i+1];   //前移                                if (orders[i]==null){                                    isDelete=true;                                    break;                                }                            }                        }                    }                    }while (n<1||n>e||"已完成".equals(orders[n][1]));                    break;//我要点赞----------------------------------------------------------------------------                case 5:                    System.out.println("***我要点赞***");                    int hp=0;                    System.out.println("请选择点赞菜品:");                    hp=sc.nextInt();                    if (hp<1||hp>dishes.length){                        System.out.println("对不起,输入有误,请重新输入!");                    }else{                        hot[hp-1]++;                    }                    break;//退出系统------------------------------------------------------------------------------------                default:                    System.out.println("6、退出系统");            }//switch结束--------------------------------------------------------------------------------------            if (chose>0&&chose<6){                System.out.println("输入0返回!");                chose=sc.nextInt();            }else {                break;            }//-----------------------------------------------------------------------------        }while (chose==0);        System.out.println("输入0返回!");    }}

以上是“如何使用Java实现简单点餐系统”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯