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

重写吃货联盟

时间:2019-07-27 12:39:44      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:封装   ima   ring   c4c   ide   b2c   ice   time()   count()   

 

技术图片需求:根据所学面的向对象以及集合知识,重写吃货联盟

技术图片
 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, double price, int zan) {
11         super();
12         this.num = num;
13         this.muneNmae = muneNmae;
14         this.price = price;
15         Zan = zan;
16     }
17     public int getNum() {
18         return num;
19     }
20     public void setNum(int num) {
21         this.num = num;
22     }
23     public String getMuneNmae() {
24         return muneNmae;
25     }
26     public void setMuneNmae(String muneNmae) {
27         this.muneNmae = muneNmae;
28     }
29     public double getPrice() {
30         return price;
31     }
32     public void setPrice(double price) {
33         this.price = price;
34     }
35     public int getZan() {
36         return Zan;
37     }
38     public void setZan(int zan) {
39         Zan = zan;
40     }
41 }
42 
43 
44 
45 
46 /**
47  * @author Administrator
48  *    菜单初始化以及编写响应功能
49  */
50 public class MuneInfo {
51     public static Mune[] mune = new Mune[10];
52     static {
53         //菜品名、价格、点赞数
54         mune[0] = new Mune(1, "红烧带鱼", 38.0, 555);
55         mune[1] = new Mune(2, "鱼香肉丝", 15.0, 333);
56         mune[2] = new Mune(3, "时令鲜疏", 10.0, 222);
57     }
58     
59     //打印菜单
60     public static void toprint() {
61         System.out.println("序号\t\t菜名\t\t单价\t\t点赞数\t\t");
62         for(Mune mu : mune) {
63             if(mu != null) {
64                 System.out.println(mu.getNum()+"\t\t"+mu.getMuneNmae()+"\t\t"+mu.getPrice()+"\t\t"+mu.getZan());
65             }
66         }
67     }
68     
69     //查询菜单
70     public static void findInfo(int i) {
71         System.out.println("序号\t\t菜名\t\t单价\t\t点赞数\t\t");
72         System.out.println(mune[i-1].getNum()+"\t\t"+mune[i-1].getMuneNmae()+"\t\t"
73         +mune[i-1].getPrice()+"\t\t"+mune[i-1].getZan());
74     }
75 }
菜单以及初始化菜单和编写菜单相关功能
技术图片
/**
 * @author Administrator
 *    餐袋信息
 */
public class OrderInfo {
    private int xuhao;//序号
    private String names;//用户名字
    private String Dishes;//菜品
    private int count;//份数
    private int time;//送餐时间
    private String address;//送餐地址
    private double moneys;//总价格
    private String state;//订单状态
    public OrderInfo(int xuhao, String names, String dishes, int count, int time, String address, double moneys,
            String state) {
        super();
        this.xuhao = xuhao;
        this.names = names;
        Dishes = dishes;
        this.count = count;
        this.time = time;
        this.address = address;
        this.moneys = moneys;
        this.state = state;

    }
    public int getXuhao() {
        return xuhao;
    }
    public void setXuhao(int xuhao) {
        this.xuhao = xuhao;
    }
    public String getNames() {
        return names;
    }
    public void setNames(String names) {
        this.names = names;
    }
    public String getDishes() {
        return Dishes;
    }
    public void setDishes(String dishes) {
        Dishes = dishes;
    }
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public int getTime() {
        return time;
    }
    public void setTime(int time) {
        this.time = time;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public double getMoneys() {
        return moneys;
    }
    public void setMoneys(double moneys) {
        this.moneys = moneys;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
}






import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class OrderInfoInit {
    public static List<OrderInfo> orderinfo = new ArrayList<>();
    //public static OrderInfo[] orderinfo = new OrderInfo[10];
    static {
        orderinfo.add(new OrderInfo(1,"张三","红烧鱼",1,14,"天成路207号",38.0,"已完成"));
        orderinfo.add(new OrderInfo(2,"李四","鱼香肉丝",2,14,"天成路207号",38.0,"已预订"));
    }
    
    public static void toprint() {
        System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
        Iterator<OrderInfo> it = orderinfo.iterator();
        while(it.hasNext()) {
            OrderInfo str = it.next();
            System.out.println(str.getXuhao()+"\t\t"+str.getNames()
            +"\t\t"+str.getDishes()+"\t\t"+str.getCount()+"\t\t"+str.getTime()+"\t\t"
                    +str.getAddress()+"\t"+str.getMoneys()+"\t\t"+str.getState());
        }
    }
    
    public static void findInfo(int i) {
        System.out.println("序号\t\t订餐人\t\t餐品信息\t\t份数\t\t送餐时间\t\t送餐地址\t\t总金额\t\t订单状态");
        System.out.println(orderinfo.get(i-1).getXuhao()+"\t\t"+orderinfo.get(i-1).getNames()
        +"\t\t"+orderinfo.get(i-1).getDishes()+"\t\t"+orderinfo.get(i-1).getCount()+"\t\t"
                +orderinfo.get(i-1).getTime()+"\t\t"+orderinfo.get(i-1).getAddress()
                +"\t\t"+orderinfo.get(i-1).getMoneys()+"\t\t"+orderinfo.get(i-1).getState());
    }
}
封装订单以及初始化订单和编写功能操作
技术图片
/**
 * @author Administrator
 *    显示操作界面
 */
public class View {
    public static void view() {
        System.out.println("欢迎使用“吃货联盟订餐系统!”");
        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("********************");
    }
}




/**
 * @author Administrator
 *    操作功能界面
 */
public class UserView {
    public static void userview() {
        View.view();
        System.out.println("请选择:");
        String choose = TestDome.input.next();
        switch (choose) {
        //我要订餐
        case "1":
            orderFood();
            break;
        //查看餐袋
        case "2":
            lookOver();
            break;
        //签收订单
        case "3":
            signFor();
            break;
        //删除订单
        case "4":
            delete();
            break;
        //我要点赞
        case "5":
            dianzan();
            break;
        //退出系统
        case "6":
            exit();
            break;

        default:
            //客户输入0~6以外的数字皆默认不使用本系统
            TestDome.flag= false;
            break;
        }

    }
        
    
    //订餐方法
    private static void orderFood() {
        System.out.println("****我要订餐****");
        MuneInfo.toprint();
        System.out.print("请输入订餐人姓名:");
        String name = TestDome.input.next();
        boolean flag1 = false;
        System.out.print("请选择您要点的菜单编号:");
        int dex;
        do {

            dex = TestDome.input.nextInt();
            if (dex >= 1 && dex <= 3) {
                break;
            } else {
                System.out.print("您选择的菜单编号不存在,请重新选择:");
                flag1 = true;
            }
        } while (flag1);
        String dishes = MuneInfo.mune[dex - 1].getMuneNmae();
        System.out.print("请输入您需要的分数:");
        int num = TestDome.input.nextInt();
        double moneys = MuneInfo.mune[dex - 1].getPrice() * num;
        System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
        int time;
        do {
            time = TestDome.input.nextInt();
            if (time >= 10 && time <= 20) {
                break;
            } else {
                flag1 = true;
                System.out.print("您输入的时间不在送餐时间内,请重新输入(送餐时间是10点至20点间整点送餐):");
            }
        } while (flag1);
        System.out.print("请输入您的送餐地址:");
        String address = TestDome.input.next();
        String state = "已预订";
        int num1 = OrderInfoInit.orderinfo.size();
        OrderInfoInit.orderinfo.add(new OrderInfo(num1+1, name, dishes, num, time, address, moneys, state));
        System.out.println("恭喜您订餐成功!订单详情如下:");
        OrderInfoInit.findInfo(num1+1);;
    }

    //查看餐袋方法
    private static void lookOver() {
        System.out.println("****查看餐袋****");
        OrderInfoInit.toprint();
    }
    //签收订单方法
    private static void signFor() {
        boolean flag1 = true;
        System.out.println("****签收订单****");
        OrderInfoInit.toprint();
        int num;
        do {
            System.out.println("请选择要签收的订单序号:");
            num = TestDome.input.nextInt();
            if(OrderInfoInit.orderinfo.get(num-1).getState() == "已完成") {
                System.out.println("该订单已完成,无法重复签收,请重新选择需要签收的订单序号!");
            }else {
                flag1 = false;
                OrderInfoInit.orderinfo.get(num-1).setState("已完成");
                System.out.println("订单签收成功!");
                
                break;
            }
        }while(flag1);
        OrderInfoInit.findInfo(num);
    }
    //删除方法
    private static void delete() {
        boolean flag11 = true;
        System.out.println("****删除订单****");
        OrderInfoInit.toprint();
        do {
            System.out.println("请选择您需要删除的订单序号:");
            int num = TestDome.input.nextInt();
            if(num > OrderInfoInit.orderinfo.size()) {
                System.out.println("该订单序号不存在,请重新选择您要删除的订单序号!");
            }else {
                flag11 = false;
                if( num <= OrderInfoInit.orderinfo.size()) {
                    OrderInfoInit.orderinfo.remove(num-1);
                }
                for(int i = 0;i < OrderInfoInit.orderinfo.size();i++) {
                    OrderInfoInit.orderinfo.get(i).setXuhao(i+1);
                }
                System.out.println("订单删除成功!");
                OrderInfoInit.toprint();
            }
        }while(flag11);
    }
    //点赞方法
    private static void dianzan() {
        boolean flag2 = true;
        System.out.println("****我要点赞****");
        MuneInfo.toprint();
        do{
            System.out.println("请选择您要点赞的菜品序号:");
            int i = TestDome.input.nextInt();
            if(i<=MuneInfo.mune.length) {
                flag2 = false;
                MuneInfo.mune[i-1].setZan(MuneInfo.mune[i-1].getZan()+1);
                System.out.println("点赞成功!");
                MuneInfo.findInfo(i);
                break;
            }else {
                System.out.println("您选择的菜品序号不存在,请重新选择!:");
            }
        }while(flag2);
    }
    private static void exit() {
        System.out.println("****退出系统****");
        TestDome.flag = false;
        
    }
}
用户操作界面
技术图片
 1 import java.util.Scanner;
 2 
 3 /**
 4  * @author Administrator
 5  *    测试类
 6  */
 7 public class TestDome {
 8     static Scanner input = new Scanner(System.in);
 9     static boolean flag = true;//返回是否退出系统
10     static int num0;//为0返回菜单
11     public static void main(String[] args) {
12         do{
13             UserView.userview();
14             if(!flag==true) {
15                 break;
16             }else {
17                 System.out.println("请输入0返回菜单");
18                 num0 = input.nextInt();
19             }
20         }while(num0 == 0);
21         System.out.println("谢谢使用,欢迎下次光临!");
22     }
23 }
测试类

测试运行结果:

查看餐袋信息:

技术图片

实现订餐:

技术图片

订完餐后查看餐袋:

 

技术图片

签收订单:

技术图片

删除订单:

技术图片

点赞以及退出系统:

技术图片技术图片

 

重写吃货联盟

标签:封装   ima   ring   c4c   ide   b2c   ice   time()   count()   

原文地址:https://www.cnblogs.com/Dean-0/p/11254495.html

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