模拟共享餐厅

共享经济如火如荼,共享单车,共享雨伞,共享充电器,现在又出来一个共享餐厅。

什么是“共享餐厅”?消费者通过APP订购附近(同一建筑或800m内)餐饮单位制作的餐食,餐厅提供就餐场所并自备餐具到制作餐食的餐饮单位取餐

本程序模拟共享餐厅就餐业务。程序的运行结果如下所示:


为两者提供的服务主要有:(1)为消费者:开台,点餐,就餐,结算;(2)为餐饮制作单位:取餐,菜单管理,注册,注销。


主要的业务流程如下:共享餐厅准备基础数据,用户开台,用户点餐,餐饮单位制作食物,工作人员取餐,用户用餐,结算,关台。

在这个业务中,设计到了类图如下:


各个类图详情描述如下:




Dish.java

package com.hnevc.sharerestuarnt;

public class Dish {
	private int dishId;
	private String name;
	private CookRestaurant cookeRestaurant;
	private int price;
	public CookRestaurant getCookeRestaurant() {
		return cookeRestaurant;
	}
	public String getName() {
		return name;
	}
	public int getPrice() {
		return price;
	}
	public void setCookeRestaurant(CookRestaurant cookeRestaurant) {
		this.cookeRestaurant = cookeRestaurant;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getDishId() {
		return dishId;
	}
	public void setDishId(int dishId) {
		this.dishId = dishId;
	}
	public Dish() {
		// TODO Auto-generated constructor stub
	}
	public Dish(String name,CookRestaurant cookRestaurant, int price) {
		this.name = name;
		this.cookeRestaurant = cookRestaurant;
		this.price = price;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return dishId+"\t"+name+"\t"+cookeRestaurant+"\t"+price;
	}
}

Order.java

package com.hnevc.sharerestuarnt;

import java.util.ArrayList;

public class Order {
	int status;//0 表示未结账,1表示已结账
	Desk desk;
	User user;
	int orderId;
	ArrayList<Dish> dishs = new ArrayList<>();
	public ArrayList<Dish> addDish(Dish dish) {
		dishs.add(dish);
		return dishs;
	}
	public ArrayList<Dish> getDishs() {
		return dishs;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public int getStatus() {
		return status;
	}
	public Order() {
		// TODO Auto-generated constructor stub
	}
	public Order(int orderId,User user, Desk desk) {
		this.orderId = orderId;
		this.user = user;
		this.desk = desk;
		this.status =0;
	}
	public Order(int orderId,User user) {
		this.orderId = orderId;
		this.user = user;
		this.status =0;
	}
	
	public Desk getDesk() {
		return desk;
	}
	public User getUser() {
		return user;
	}
	public void setDesk(Desk desk) {
		this.desk = desk;
	}
	public void setUser(User user) {
		this.user = user;
	}
}

Desk.java

package com.hnevc.sharerestuarnt;

public class Desk {
	private String deskName;
	private Order order;
	private User user;
	private int status;//0 未使用, 1使用
	public Desk() {
		// TODO Auto-generated constructor stub
	}
	public Desk(String deskName) {
		this.deskName = deskName;
	}
	
	public String getDeskName() {
		return deskName;
	}
	public void setDeskName(String deskName) {
		this.deskName = deskName;
	}
	public Order getOrder() {
		return order;
	}
	public void setOrder(Order order) {
		this.order = order;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public User getUser() {
		return user;
	}
	public void setStatus(int status) {
		status = status;
	}
	public int getStatus() {
		return status;
	}
	public void clear() {
		order = null;
		user =null;
		status =0;
	}
	
}


CookRestaurant.java

package com.hnevc.sharerestuarnt;

import java.util.ArrayList;
public class CookRestaurant {
	private String name;
	private ArrayList dishes = new ArrayList<>();
	public CookRestaurant(String name) {
		this.name =name;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public ArrayList<Dish> getDishes(){
		return dishes;
	};
	public void cookDish(Dish dish){
		System.out.println("餐饮单位:"+name+"正在制作:"+dish.getName());
	};
	public void sendDish(Dish dish){
		System.out.println("餐饮单位:"+name+"正在配送:"+dish.getName());
	};
	public void addDish(Dish dish){
		dishes.add(dish);
	}
	public void removeDish(Dish dish){
		dishes.remove(dish);
	}
	public Dish getDish(int index){
		return (Dish)(dishes.get(index));
				
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return name+"\t";
	}
}

User.java

package com.hnevc.sharerestuarnt;

public class User {
	private String userName;
	private String password;
	public String getPassword() {
		return password;
	}
	public String getUserName() {
		return userName;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public User(String userName,String password) {
		this.userName = userName;
		this.password = password;
	}
	public User() {
		// TODO Auto-generated constructor stub
	}
	
}

ShareRestaurant.java


package com.hnevc.sharerestuarnt;

import java.util.ArrayList;

public class ShareRestaurant {
	private ArrayList<Desk> desks = new ArrayList<>();
	private ArrayList<User> users = new ArrayList<>();
	
	private ArrayList<CookRestaurant> cookRestaurants = new ArrayList<>();

	public ArrayList<CookRestaurant> getCookRestaurants() {
		return cookRestaurants;
	}

	public ArrayList<Desk> getDesks() {
		return desks;
	}
	
	public ArrayList<User> getUsers() {
		return users;
	}

	public User login(User user){
		return user;
	}
	public void addCookeRestaurant(CookRestaurant cookRestaurant){
		cookRestaurants.add(cookRestaurant);
	}
	public void addUser(User user) {
		users.add(user);
	}
	public void addDesk(Desk desk){
		desks.add(desk);
	}
	
	public Desk openDesk(Desk desk,User user){
		System.out.println(user.getUserName() +"开台========");
		desk.clear();
		desk.setUser(user);
		return desk;
	}
	public void closeDesk(Desk desk){
		System.out.println("关台========");
		desk.clear();
	}

	public void payBill(Desk desk) {
		// TODO Auto-generated method stub
		System.out.println("结算");
		int sum=0;
		for(int i=0;i<desk.getOrder().getDishs().size();i++){
			Dish d = desk.getOrder().getDishs().get(i);
			sum += d.getPrice();
		}
		System.out.println("共消费"+sum+"元"+desk.getUser().getUserName()+"请付费:"+sum+"元");
	}
	public void getFoodsForDesk(Desk desk) {
		System.out.println("系统根据order 到各个餐饮单位取餐");
		for(int i=0;i<desk.getOrder().getDishs().size();i++){
			Dish d = desk.getOrder().getDishs().get(i);
			d.getCookeRestaurant().cookDish(d);
			d.getCookeRestaurant().sendDish(d);
		}
	}


}






阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页