Java小项目(二)---外卖订餐系统

一、使用技术

Java SE

二、实现功能

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

三、运行效果图

3.1 订餐功能

在这里插入图片描述

3.2 查看餐袋

在这里插入图片描述

3.3 签收订单

在这里插入图片描述

3.4 删除订单

在这里插入图片描述

3.5 点赞

在这里插入图片描述

3.6 退出

在这里插入图片描述

四、实现的代码

4.1 Food 菜单类

public class Food {
    //菜单类:序号、菜名、单价
    private int id;
    private String name;
    private double price;
    //无参构造方法

    public Food() {
    }
    //有参构造方法


    public Food(int id, String name, double price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }
    //重写toString方法

    @Override
    public String toString() {
        return id+"\t"+name+"\t"+price+"元";
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    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;
    }
}

4.2 Memu订单类

public class Memu {
    //订单类:序号、订餐人、餐品信息、送餐日期、送餐地址、总金额、订单状态
    private int id;
    private String name;
    private String foodMes;
    private int time;
    private String address;
    private double money;
    private  String now;
    //无参构造方法

    public Memu() {
    }
    //有参构造方法

    public Memu(int id, String name, String foodMes, int time, String address, double money, String now) {
        this.id = id;
        this.name = name;
        this.foodMes = foodMes;
        this.time = time;
        this.address = address;
        this.money = money;
        this.now = now;
    }
    //重写toString方法

    @Override
    public String toString() {
        return id+"\t"+name+"\t"+foodMes+"\t"+time+"点\t"+address+"\t"+money+"元\t"+now;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public String getFoodMes() {
        return foodMes;
    }

    public void setFoodMes(String foodMes) {
        this.foodMes = foodMes;
    }

    public int getTime() {
        return time;
    }
    //增加时间输入的判断
    public void setTime(int time) {
        if (time>=10&&time<=20){
            this.time = time;
        }else{
            System.out.println("输入错误,默认12点送餐");
            this.time = 12;
        }

    }

    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 getNow() {
        return now;
    }

    public void setNow(String now) {
        this.now = now;
    }
}

4.3 OrderMange外卖订餐系统测试类

import java.util.Scanner;

public class OrderMange {
    //外卖订餐系统测试类
    public static void main(String[] args) {
        //1.定义Food对象数组并赋值
        Food[] foods=new Food[3];
        foods[0]=new Food(1,"红烧茄子",24.0);
        foods[1]=new Food(2,"红烧排骨",36.0);
        foods[2]=new Food(3,"鱼香肉丝",32.0);
        //2.定义Scanner对象
        Scanner sc = new Scanner(System.in);
        //3.定义菜单对象和订单序号
        Memu memu1 = new Memu();
        memu1.setId(1);
        //4.定义循环控制变量
        boolean isFood=true;
        //5.定义返回0循环控制变量和num0
        boolean is0=true;
        int num0=1;
        //6.定义点赞数和数组
        int[] goodNum={0,0,0};
        System.out.println("欢迎使用“外卖订餐系统”");
        while (isFood){
            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 choseNum = sc.nextInt();//7.定义选择的数字
            switch (choseNum){
                case 1:
                    System.out.println("***我要订餐***");
                    System.out.print("请输入订餐人姓名:");
                    memu1.setName(sc.next());
                    //8.菜单显示
                    System.out.println("序号\t"+"菜名\t"+"单价");
                    for (int i = 0; i < foods.length; i++) {
                        System.out.println(foods[i].toString());
                    }
                    System.out.print("请选您要点的菜品编号:");
                    int foodId = sc.nextInt();
                    //9.菜品编号判断1-3,否则返回
                    if (foodId>=1&&foodId<=3){

                    }else{
                        System.out.println("输入错误,菜品编号需要输入1-3的整数");
                        break;
                    }
                    System.out.print("请选择您需要的份数:");
                    int foodNumber = sc.nextInt();
                    if(foodId==1){
                        memu1.setFoodMes("红烧茄子\t"+foodNumber+"份");
                    }else if(foodId==2){
                        memu1.setFoodMes("红烧排骨\t"+foodNumber+"份");
                    }else if(foodId==3){
                        memu1.setFoodMes("鱼香肉丝\t"+foodNumber+"份");
                    }
                    System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐)");
                    memu1.setTime(sc.nextInt());
                    System.out.print("请输入送餐地址:");
                    memu1.setAddress(sc.next());
                    System.out.println("订餐成功!");
                    System.out.println("您订的是:"+memu1.getFoodMes());
                    System.out.println("送餐时间:"+memu1.getTime()+"点");
                    memu1.setMoney(foods[foodId-1].getPrice()*foodNumber+6.0);
                    System.out.println("餐费:"+foods[foodId-1].getPrice()*foodNumber+"元,送餐费:6.0元,总计:"+memu1.getMoney()+"元.");
                memu1.setNow("已预订");
                  //10.输入0才返回判断输入的值为0才返回
                    while (is0){
                        System.out.print("输入0返回:");
                         num0 = sc.nextInt();
                        if (num0==0){
                            is0=false;
                        }
                    }
                    break;
                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序号\t"+"订餐人\t"+"餐品信息\t"+"送餐日期\t"+"送餐地址\t"+"总金额\t"+"订单状态");
                    System.out.println(memu1.toString());
                    //循环变量初始化
                    is0=true;
                    //判断输入的值为0才返回
                    while (is0){
                        System.out.print("输入0返回:");
                         num0 = sc.nextInt();
                        if (num0==0){
                            is0=false;
                        }
                    }
                    break;
                case 3:
                    System.out.println("***签收订单***");
                    System.out.print("请选择要签收的订单序号:");
                    int num3 = sc.nextInt();
                    //和当前订单序号进行判断
                    if (num3==memu1.getId()){
                        System.out.println("订单签收成功!");
                    }else{
                        System.out.println("签收失败!没有这个订单!");
                    }
                    //循环变量初始化,判断输入的值为0才返回
                    is0=true;
                    while (is0){
                        System.out.print("输入0返回:");
                        num0 = sc.nextInt();
                        if (num0==0){
                            is0=false;
                        }
                    }
                    break;
                case 4:
                    System.out.println("***删除订单***");
                    System.out.print("请输入要删除的订单序号:");
                    int num4 = sc.nextInt();
                    //和当前订单序号进行判断
                    if (num4==memu1.getId()){
                        System.out.println("删除订单成功!");
                    }else{
                        System.out.println("删除订单失败!没有这个订单!");
                    }
                    //循环变量初始化,判断输入的值为0才返回.
                    is0=true;
                    while (is0){
                        System.out.print("输入0返回:");
                         num0 = sc.nextInt();
                        if (num0==0){
                            is0=false;
                        }
                    }
                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    //6.菜单显示
                    System.out.println("序号\t"+"菜名\t"+"单价");
                    for (int i = 0; i < foods.length; i++) {
                        System.out.println(foods[i].toString()+"\t"+goodNum[i]+"赞");
                    }
                    System.out.print("请输入要点赞的菜品序号:");
                    int num5 = sc.nextInt();
                    if (num5>=1&&num5<=3){

                    }else{
                        System.out.println("输入错误,菜品序号需要输入1-3的整数");
                        break;
                    }
                    for (int i = 0; i <foods.length ; i++) {
                        if(num5==foods[i].getId()){
                            goodNum[i]++;
                        }
                    }
                    //循环变量初始化,判断输入的值为0才返回
                    is0=true;
                    while (is0){
                        System.out.print("输入0返回:");
                         num0 = sc.nextInt();
                        if (num0==0){
                            is0=false;
                        }
                    }
                    break;
                case 6:
                    System.out.println("谢谢使用,欢迎下次光临!");
                    isFood=false;
                    break;
                default:
                    break;
            }
        }
    }
}

java项目package project.action.dialogAction; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import project.dao.common.DbException; import project.dao.dataDao.LoginInfoDao; import project.dao.dataDaoImpl.LoginInfoDaoImpl; import project.view.dialog.AddLoginInfoDialog; import project.vo.LoginInfoVo; /** * 添加登录账号action * * @author Administrator * */ public class AddLoginInfoAction implements ActionListener { private AddLoginInfoDialog dialog; public AddLoginInfoAction(AddLoginInfoDialog dialog) { this.dialog = dialog; } public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); if (name.equals("确定")) { // 检验输入是否正确 if (dialog.checkInputValue()) { LoginInfoDao dao = null; LoginInfoVo vo = null; try { // 获得界面输入信息 vo = dialog.getInputInfo(); String confirm = dialog.getConfirm(); if (vo.getLog_pwd().equals(confirm)) { dao = new LoginInfoDaoImpl(); if (dao.insertLoginInfo(vo)) { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员成功", "提示信息", JOptionPane.YES_OPTION); dialog.dispose(); } else { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员失败", "提示信息", JOptionPane.YES_OPTION); } } else { // 如果密码确认输入错误,打印提示信息 JOptionPane.showMessageDialog(null, "密码确认错误,请重新输入", "提示信息", JOptionPane.YES_OPTION); } } catch (DbException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "提示信息", JOptionPane.YES_OPTION); } } else { JOptionPane.showMessageDialog(null, "请确认输入是否完整正确", "提示信息", JOptionPane.YES_OPTION); } } else if (name.equals("取消")) { dialog.dispose(); } } }
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱喝皮蛋瘦肉粥的小饶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值