Reservation system for Internet restaurants (data structures)

I have a task to develop an online booking system. If the user can enter the zip code / no people / time of booking and get a list of restaurants. Assumption (User and restaurant are always in the same city)

Each restaurant may have several tables with a different number of seats. So, 2 tables that accommodate 4 people and 4 tables that hold 4 people.

I am having problems with the correct data structures.

My classes are as follows

Restaurant : contains opening time, timeOfClosing, totalNoOfSeatsAvailable Not sure how I will store information in a table in a restaurant. It does not make sense to have a separate class for the table. All I need is howManytables for free and what are their sizes.

Reservation This saves the actual reservation and allows you to cancel the reservation.

Backup system : contains an interface for "List checkAvailability (long time, int people)" How will this return this list? Initially, I was thinking about using Queue priority to maintain a queue with as many places as possible. But then I will look through this list to see if the time is right to make a reservation, and then after the reservation is made, refresh this queue. One of the problems is that the queue makes all duplicates.

My specific questions are:

  • How to store information in a table in each restaurant.
  • What is the best way to keep this list of restaurants so that I can return the list without having to sort this information every time.

EDIT: Asked how to store information in a table. My special thing is that saving the table class means that I create unnecessary objects. Here are my thoughts. 5 tables in which 2 people are placed have the same objects - I mean that there is no important information that will differ from them. I just need numbers. no seats / table. (If I have a table of 4, but 3 people, I will consider this table)

I was thinking about creating 3 arrays. Suppose the table represents 1,2, etc., therefore int [] differentSeatingOnTable; its indexes are tables, and values ​​are allowed places. Then an array of tables with totalNoOfThosetable, where indexes are tables and values, are the total number of such a table. Similary for free tables freeTables, where the index is a table and how much of such a free table is left.

+4
source share
3 answers

1.) If you just store the number of seats in a restaurant, you shoot in the foot. Suppose I need to place an order for 16 people, and they should all be on the same table (yes, I need a rather long table). Your system can pick up my guests somewhere where they have to sit in 8 tables for two people.

You need a table class. Then your restaurants should have a collection of tables. If you want to find out how many seats you have in a restaurant, you just need to go through your collection of tables and count the seats. And if you want to know if you can sit in the same family in one table in a restaurant, you just need to check if she has a table with so many seats.

EDIT: There is a more minimalistic way of storing restaurant seats. Use a dictionary, hash table, or any other structure that contains keys and associated values. Thus, the key is a table type. The key can be an integer saying how many people are sitting at the table. The value represents the number of tables of this type present in the restaurant. I think this is much better than my initial suggestion.

So, for example, a restaurant with such a hash table:

Key | Value 4 | 5 2 | 8 16 | 1 

It has five tables with 4 seats each, 8 tables with 2 seats each and one long table that seats 16 people. (Also using a table to store tables is so meta).

2.) Your rationale is suitable for reservations. If it does duplicates, you should post a more specific question showing how you are doing this so that we can try to find the error.

+4
source

Relational databases simplify both of these requirements.

You will have two tables: RESTAURANT and SITTING (TABLE is a reserved word in SQL) with a one-to-many relationship between them.

The RESTAURANT will have a name, so you can specify the name ORDER BY.

 package model; class Table { private int id; private int numSeats; public Table(int id, int numSeats) { this.id = id; this.numSeats = numSeats; } public int getId() { return this.id; } public int getNumSeats() { return this.getNumSeats; } } class Restaurant implements Comparable { private String name; private List<Table> tables; public Restaurant(String name) { this.name = name; this.tables = new ArrayList<Table>(); } public void addTable(Table t) { this.tables.add(t); } public void removeTable(int id) { for (Table t : this.tables) { if (t.getId() == id) { this.tables.remove(t); break; } } } public int getCapacity() { int capacity = 0; for (Table t : this.tables) { capacity += t.getNumSeats(); } return capacity; } public int compareTo(Restaurant r) { return this.name.compareTo(r.name); } } 
+1
source

1) good .. I think it makes sense if you created the table.its class easier than trying to frantically digest it in a restaurant class. And it will be easier for you too

2) maintain the primary key field, maybe a composite key denoting uniques, this may contain duplicates

: RECOMMENDATIONS Class Res_Table Restaurant class

ORDER primary key fields

0
source

Source: https://habr.com/ru/post/1497596/


All Articles