Section 15.3 - CSE 102: Algorithmic Thinking and Programming

15.3 SS21 Project 3 Manage Restaurant Seating


Overview

In this project, you will be creating a program to help a popular restaurant manage their waiting line for seats.


Objectives

Think about how to create a more complicated program by breaking it into manageable pieces.

● Understand how to use a menu of possible actions repeatedly with a sentinel loop

● Understand how to add and remove elements of a list using Python list methods

● Use functions and incremental development to make a complicated program manageable


Description

Imagine that we are creating an app for the host/hostess at a busy restaurant to manage the line of customers waiting to be seated. As customers arrive, they are asked their party size, and they are added to the end of a waiting queue. Similar to other restaurants there is a VIP program here. If customers show a VIP card when checking in, they are given priority and added to the beginning of the waitlist (behind other VIP customers). When a table of diners is cleared there now are "n" number of seats available for a party from the waitlist to be seated as long as the group is of size n or smaller. To simplify our programming, we are going to be concerned only with total seat management and not with optimizing table usage. We will assume that the tables and chairs are infinitely configurable, so that empty tables from smaller parties can be pushed together to accommodate larger parties, and small parties will take up only the number of spots for their own party (i.e., you don't need to worry about unused seats at tables or table sizes). When there is space available for the next party, the host/hostess will call out the name of the next party in line. That party will then be seated and they will be removed from the waitlist. The app will also provide for other capabilities such as the ability to display the current queue so that customers can see their current position in the waitlist.

The first thing that the program needs to do is ask the user for the capacity of the restaurant. This will be used to determine if someone can be seated. When the restaurant is at full capacity (fewer available seats than customers wanting seats), people can still join the queue, but no one can be seated until a table is cleared.

The restaurant will manage the queue via a menu you need to implement into your program. Menu options and presentation format are illustrated below. Your program will need to display the menu of options available, and you will need to prompt the host/hostess for their selection of option. To make the program more user friendly, the user should be able to choose their option by either entering in the menu option number or a short abbreviation (e.g., first few words) of the menu option action they wish to run. If they are using a menu option abbreviation they can enter it in any case -- upper, lower, or mixed. One of the requirements for the project is that you must implement the processing related to displaying the menu and soliciting the user option in a function called getMenuChoice. This function will have no parameters so no arguments will be passed to it, however, the function must return an integer number representing the user's choice of menu option, whether the option was selected by number or by abbreviation. The menu should display to the user in the following format/content:

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

The user can select an option by either the option number, or by entering a phrase which starts with any of the following abbreviations which tie to each menu option respectively.

  add party
  add VIP
  seat
  clear
  remove
  print wait
  print tables
  exit

Regardless of how an option is selected, you will return an integer value. If the user enters:

● 4, you will return 4

● clear, you will return 4

● CLEAR THE TABLE, you will return 44/6/2021

● Add Party of 10, you will return 1

● Add a new party, you will display a message Unknown menu option. If this error is made, you should redisplay the menu and reprompt the user for an option selection.

● 9, you will display the error message noted above , redisplay the menu and reprompt the user for an option selection.

The getMenuChoice function should be called from the main program with no arguments and take the integer value that is returned to route processing to the appropriate instructions to handle that menu option.

Next, let's look at what the main program will need to do with each of these options. As a reminder, the program must initially get the restaurant capacity in number of seats from the user before doing anything with individual option processing. The capacity will become critical for determining if you can seat additional parties. On restaurant opening, the waitlist queue will have nothing in it. However, the queue will ebb and flow throughout the day as customers arrive, eat, and leave.

Different menu options will be taken based on the particular action the host/hostess are processing. We have described each of the various actions by menu option below.

When customers arrive to the restaurant, they will be added to the queue via either option 1 or 2. If they are not a VIP customer, they will be added to the queue through option 1. If they are a VIP customer (as verified by the host/hostess), they will be added to the queue through option 2. Regardless of which option is used, you will need to ask for customer name and number of guests in their party.

1. Add party to the queue. When a non-VIP customer is added to the queue, you will ask for the customer's name and their party size. You will need to track this information for later use. Because the non-VIP customer does not receive preferential treatment, you will then add them to the end of the queue.

2. Add VIP party to the queue. When a VIP customer is added to the queue, you will also ask for the customer's name and their party size. Like with the non-VIP customers you will record this information for later use. Unlike the non-VIP customers, you will not place the VIP customer at the end of the waiting queue. Rather, you will put the new VIP customer in front of any non-VIP customers but after any previously waiting VIP customers. In other words, a new VIP customer will get priority in the waiting line over non-VIP customers but will not be able to "cut" in front of other VIP customers who are already in line.

3. Seat a party. When the host/hostess selects this option, you will attempt to seat the next party in line. Any number of things might happen here. If the number of seats currently available in the restaurant can accommodate the size of the next party in line then you can seat that party. If you are able to seat that party, you should:

● Display a message with the following content/format: Now seating Jon party of 5.

● Remove Jon's party from the waiting queue

● Record Jon's party as seated

● Make necessary adjustments to restaurant capacity4/6/2021

If you are not able to seat the next party in queue because there are not enough available seats, you should display the message Can't seat Jon party of 5 until more tables are cleared.

If there are no parties in queue when this option is selected, you should display the message No customers to seat.

*A couple of additional comments regarding seating: You do not need to do any queue optimization. If there are 3 open seats and the next party has 5 members followed by a party with 2 members, you do not need to consider the party second in line. *Your only decision criteria in seating is first in queue, first to be seated regardless of party size and seat availability.*

4. Clear a table. When the host/hostess selects "clear a table", you will need to prompt them for the name of the party to be cleared. Continuing our prior example, if the host/hostess selected Jon one of two things need to happen:

● if Jon's party was in fact seated, you should:

Display the message Clearing table for Jon party of 5.

○ Restore the seats used by Jon's party as available

○ Remove them from the seated list

● if Jon's party was not seated, you should:

○ Display the message No party by that name eating.

An additional clarification. You do not need to worry about two parties with the same name. There will never be two different parties with the same name in the restaurant at the same time.

5. Remove a party. If someone gets tired of waiting or leaves, the host/hostess will take them off the waiting queue via option 5. If selected, the host/hostess will need to specify the name of the party. That party then needs to be taken off the waiting queue. As with prior options, two possibilities exist:

● if the customer is on the waiting queue, you need to remove them from the queue;

● if the customer is not on the waiting queue you should display the message No party by that name waiting.

6. Print out the wait queue. If this option is selected, your program should print the waiting queue in sequence starting with first to be served through the last to be served. This output should look similar in format to the following example:

  Waiting to be seated:
        Jon party of 5
        Ben party of 2
        Anika party of 4
        Bridget party of 4

7. Print tables already seated. When this option is selected, you should report tables that are currently seated, in the order in which they were seated, and identifying VIP customers who are seated. This output should be similar in format to the following example:

  Parties currently eating:
        VIP Nicole party of 3
        Gigi party of 4
        VIP Nick party of 2

8. Exit Although this is self-explanatory, selection of this option should cause the program to end processing without any kind of error or printing of any output.


Sample Output Run

Following is an example run of what the program should look like after 'Jon', 'Ben', and 'Anika' have already been added to the queue:

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.
  
  1
  
  What is the party's name? Bridget
  How many people are in the party? 4

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.
  
  6
  
  Jon party of 5
  Ben party of 2
  Anika party of 4
  Bridget party of 4

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

  3
  Now seating Jon party of 5.

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

  6

  Waiting to be seated:
        Ben party of 2
        Anika party of 4
        Bridget party of 4

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

  7

  Parties currently eating:
        Jon party of 5

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

  4

  Which party's table is done? Jon
  Clearing table for Jon party of 5

  (1)  Add party to the queue.
  (2)  Add VIP party to the queue.
  (3)  Seat a party.
  (4)  Clear a table.
  (5)  Remove a party.
  (6)  Print wait queue.
  (7)  Print tables already seated.
  (8)  Exit.

  8


Other Details

In addition to the getMenuChoice function, you will need to create an additional function called isVIP. This function takes two arguments: a customer's name, and a list, and returns True if the customer is in the list, and False if the customer is not in the list. When the host/hostess first puts a VIP into the queue, we can assume that they checked the customer's card to verify that they indeed are a VIP. You will need to keep track of the VIPs currently in the restaurant or waiting to be seated in order to use this function correctly. If you solve your program such that you do not ever call this function, it still must exist and work correctly so that the automated unit tests will pass.

You may use other functions as you wish, which may help you to organize your code and make it understandable.

To attack a problem such as this one, you need to think about the structure of the program without getting bogged down in the details at first. It is a good strategy to get the menu and loop structure working first. To do this, for each menu option you can simply print out a statement like "add party to queue", "print the wait queue" etc as the user enters the appropriate option.

Once you know that one part is working correctly, substitute the print statements with the code that will actually manipulate the queue(s). You may want to consider creating a function for each (or some) of the menu options.


Academic Integrity

Again, a word about academic honesty. If you use a solution that is online, or submitted by other students, you will get a 0 for the project and a further 5% reduction in your grade. If you post the problem online for someone else to provide a solution, you will get a 0 for the course. In all cases, an Academic Dishonesty Report will be filed with the university.


Pseudocode

If you ask the TAs for help on this project, the first thing they will do is ask to see your thought processes. You should not write any code before you understand how the structure of the program will work, a basic feel for how you are storing and manipulating the data, and what each menu option will have to do. You need to write down the steps to form your pseudocode, which will be turned in to D2L by Apr 9. Pseudocode which merely prints out each menu option inside a loop will not receive full credit - you need some level of detail on each of the options in order to gain full credit.