码迷,mamicode.com
首页 > 其他好文 > 详细

重做订餐系统

时间:2019-07-19 17:01:54      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:==   inpu   ide   操作   bool   添加菜单   img   string   des   

技术图片
package oop;

//订单类
public class Order {
    private String name;//订餐人姓名
    private String address;//订餐地址
    private int time;//送餐时间
    private String foodName;//所订餐品名
    private int foodNum;//所订餐品份数
    private double moneys;//总金额
    private String ddzt;//订单状态

    public Order() {
    }

    public Order(String name, String address, int time, String foodName, int foodNum, double moneys, String ddzt) {
        this.name = name;
        this.address = address;
        this.time = time;
        this.foodName = foodName;
        this.foodNum = foodNum;
        this.ddzt = ddzt;
        this.moneys = moneys;
    }

    public String getName() {
        return name;
    }

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

    public String getAddress() {
        return address;
    }

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

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public String getFoodName() {
        return foodName;
    }

    public void setFoodName(String foodName) {
        this.foodName = foodName;
    }

    public int getFoodNum() {
        return foodNum;
    }

    public void setFoodNum(int foodNum) {
        this.foodNum = foodNum;
    }

    public double getMoneys() {
        return moneys;
    }

    public void setMoneys(double moneys) {
        this.moneys = moneys;
    }

    public String getDdzt() {
        return ddzt;
    }

    public void setDdzt(String ddzt) {
        this.ddzt = ddzt;
    }


}
储存顾客信息类
技术图片
package oop;

import java.util.*;
/**
 * 店家类
 */
public class Trade {
    private String name;//餐品名
    private double money; //餐品价格
    private int dds;//点赞数

    //添加菜单
    public Trade() {}

    public Trade(String name, double money,int dds) {
        this.name = name;
        this.money = money;
        this.dds =dds;
    }

    public String getName() {
        return name;
    }

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

    public double getMoney() {
        return money;
    }

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

    public int getDdz() {
        return dds;
    }

    public void setDdz(int ddz) {
        this.dds = ddz;
    }
}
店家类
技术图片
package oop;

import java.util.Scanner;

/**
 * 用户类
 */
public class User {
    static Scanner input = new Scanner(System.in);
    Order[] order = new Order[5];//顾客信息
    Trade[] trades = new Trade[5];// 菜品信息
    // 初始化信息
    public void csh() {
        for (int i = 0; i < order.length; i++) {
            trades[i] = new Trade("菜名" + (i + 1), (5 + i) * 2, 0);
            order[0] = new Order("顾客1", "地址1", 12, "菜名1", 2, 25, "已预订");
            order[1] = new Order("顾客2", "地址3", 15, "菜名1", 2, 25, "已完成");
        }
    }
    //循环操作系统
    public void run() {
        System.out.println("………………………………………………欢迎使用本订餐系统…………………………………………………");
        do {//显示操作界面
            zInfo();
            //循环操作
            int num = xianze();
            switch (num) {
                case 1:
                    boolean boo = false;
                    for (int i = 0; i < order.length; i++) {
                        if (order[i] == null) {
                            //订餐
                            dingCan(i);
                            boo = true;
                            break;
                        }
                    }
                    if (!boo) {
                        System.out.println("餐袋已满,请删除已完成订单!");
                    }
                    //选择操作    0:返回,否则退出;
                    returns();
                    break;
                case 2:
                    //查看餐袋
                    System.out.println("******查看餐袋******");
                    lookFoods();
                    returns();
                    break;
                case 3:
                    //签收订单
                    qianshou();
                    returns();
                    break;
                case 4:
                    lookFoods();
                    //删除订单
                    delete();
                    returns();
                    break;
                case 5:
                    //点赞
                    seeTrade();
                    dianzan();
                    returns();
                    break;
                case 6:
                    System.out.println("已选择退出,正在退出程序");
                    break;
                default:
                    System.out.println("输入错误,程序退出!");
                    break;
            }
            break;
        } while (true);
    }
    //点赞
    public void dianzan() {
        System.out.println("****************我要点赞*******************");
        System.out.println("请输入想点赞的餐品序号:");
        int num = input.nextInt();
        for (int i = 0; i < trades.length; i++) {
            boolean boo1 = num > 0 && num <= trades.length;
            if (boo1) {
                boolean boo2 = trades[num - 1].getName() != null;
                if (boo2) {
                    trades[num - 1].setDdz(trades[num - 1].getDdz() + 1);
                    System.out.println("点赞成功!");
                    return;
                }
            }
        }
        System.out.println("输入有误,未找到该订单!");
    }
    //删除
    public void delete() {
        System.out.println("请输入要删除的订单序号:");
        int num = input.nextInt();
        for (int i = 0; i < order.length; i++) {
            boolean boo1 = num <= order.length && num > 0;
            if (boo1 && order[num - 1] != null) {
                boolean boo3 = order[num - 1].getDdzt().equals("已预订");
                boolean boo4 = order[num - 1].getDdzt().equals(("已完成"));
                if (boo3) {
                    System.out.println("该订单未签收,不能删除!");
                    return;
                } else if (boo4) {
                    order[num - 1] = null;
                    System.out.println("成功删除该订单!");
                    return;
                }
            }
        }
        System.out.println("输入错误,未找到该订单!");
    }
    //签收
    public void qianshou() {
        System.out.println("******签收订单*****");
        lookFoods();
        System.out.println("请选择要签收的订单序号:");
        int num = input.nextInt();
        for (int i = 0; i < order.length; i++) {
            boolean boo1 = num <= order.length && num > 0;
            if (boo1 && order[num - 1] != null) {
                boolean boo3 = order[num - 1].getDdzt().equals("已预订");
                boolean boo4 = order[num - 1].getDdzt().equals(("已完成"));
                if (boo3) {
                    order[num-1].setDdzt("已完成");
                    System.out.println("签收成功!");
                    return;
                } else if (boo4) {
                    System.out.println("该订单已签收,不能重复签收!");
                    return;
                }
            }
        }
        System.out.println("输入错误,未找到该订单!");
    }
    //查看餐袋
    public void lookFoods() {
        System.out.println("序号\t订餐人\t所订餐品\t份数\t送餐时间\t送餐地址\t总金额\t订单状态");
        for (int i = 0; i < order.length; i++) {
            if (order[i] != null) {
                System.out.println((i + 1) + "、\t\t" + order[i].getName() + "\t\t" + order[i].getFoodName()
                        + "\t\t" + order[i].getFoodNum() + "\t\t" + order[i].getTime() + "\t\t\t" + order[i].getAddress()
                        + "\t\t\t" + order[i].getMoneys() + "\t" + order[i].getDdzt());
            }
        }
    }
    //操作界面
    public void zInfo() {
        System.out.println("1、我要订餐\n" + "2、查看餐袋\n" + "3、签收订单\n"
                + "4、删除订单\n" + "5、我要点赞\n" + "6、退出系统");
        System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
    }
    // 选择
    public int xianze() {
        System.out.println("请选择:");
        int num = input.nextInt();
        return num;
    }
    //订餐
    public void dingCan(int i) {
        System.out.println("*******************我要订餐********************");
        //显示菜单
        seeTrade();
        //输入订餐人信息
        tradeInfo(i);
        //输入0返回
    }
    //输入订餐人信息
    public void tradeInfo(int i) {
        System.out.println("请输入订餐人姓名:");
        String name = input.next();
        System.out.println("请输入订餐人地址:");
        String address = input.next();
        System.out.println("请输入送餐时间:");
        int time = input.nextInt();
        System.out.println("请选择所订餐品序号:");
        int x = input.nextInt();
        System.out.println("您需要订几份:");
        int f = input.nextInt();
        String foodName = trades[x - 1].getName();
        double money = trades[x - 1].getMoney() * f;
        double s_money = money > 50 ? 0 : 5;
        double moneys = money + s_money;
        String ddzt = "已预订";
        order[i] = new Order(name, address, time, foodName, f, moneys, ddzt);
        System.out.println("订餐成功!");
        System.out.println("您订单餐品是:" + foodName + ",所订份数:" + f + "份,送餐地址:" + address
                + ",送餐时间:" + time + "点,餐费:" + money + ",送餐费:" + s_money + ",总金额:" + moneys);
    }
    //显示菜单
    public void seeTrade() {
        System.out.println("序号\t" + "菜名\t" + "单价\t点赞数");
        for (int i = 0; i < trades.length; i++) {
            if (trades[i].getName() != null) {
                System.out.println((i + 1) + "\t" + trades[i].getName() + "\t" + trades[i].getMoney() + "\t" + trades[i].getDdz());
            }
        }
    }
    //输入0 返回
    public void returns() {
        System.out.println("输入0返回:");
        int num = input.nextInt();
        if (num == 0) {
            run();
        } else {
            System.out.println("系统退出!");
        }
    }
}
业务类
技术图片
package oop;

import java.util.Scanner;

public class Test {
    static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {

        User user = new User();
        user.csh();
        user.run();
    }
}
测试类

技术图片    技术图片

技术图片       技术图片

 

 

 技术图片       技术图片

 

 技术图片    技术图片

 

技术图片

 

重做订餐系统

标签:==   inpu   ide   操作   bool   添加菜单   img   string   des   

原文地址:https://www.cnblogs.com/zeng1997/p/11214120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!