**Title: Advanced Restaurant Management System**
**Introduction:**
You are tasked with creating an Advanced Restaurant Management System to streamline various
aspects of a restaurant's operations. The system will utilize Java classes and concepts, including
`ArrayDeque`, `Hashtable`, file handling with `FileWriter` and `BufferedReader`, user input, and
menu/item management. This system aims to provide functionalities such as menu management,
order placement, reservations, bill generation, and more. You will provide a detailed problem
statement and instructions for each step to guide the development of the code.
**Problem Statement:**
You are required to create a Java program for an Advanced Restaurant Management System. The
system will include the following functionalities:
1. **Menu Management:**
- Define a class `MenuItem` with attributes: `id`, `name`, `description`, and `price`.
- Create a class `Menu` that maintains a collection of menu items using an `ArrayDeque`.
- Implement a method to add menu items to the menu.
- Implement a method to display the available menu items with their IDs, names, and prices.
2. **Order Placement:**
- Define a class `Order` to represent an order.
- The `Order` class should contain `ArrayDeque` instances to store ordered items and their
quantities.
- Implement a method to add items to an order along with their quantities.
- Calculate and provide a method to calculate the total bill for an order.
3. **Reservation Management:**
- Define a class `Reservation` to store reservation details: `reservationID`, `customerName`,
`contactNumber`, `reservationDate`, and `numberOfGuests`.
- Create a `Hashtable` named `reservations` to store reservations.
- Implement a method to make a reservation and store it in the `reservations` hashtable. Assign
a unique reservation ID.
- Display reservation details including ID, customer name, contact number, reservation date, and
number of guests.
4. **Bill Generation:**
- Implement a method to generate the total bill for a reservation.
- Use the `Order` class to calculate the total bill based on the items and quantities in the order.
5. **Main Program:**
- Create a `Restaurant` class with a `main` method.
- Initialize a `Menu` instance and add initial menu items (e.g., Burger, Pasta, Salad) using the
`MenuItem` class.
- Initialize an `ArrayDeque` named `orders` to store orders.
- Initialize a `Hashtable` named `reservations` to store reservations with unique IDs.
- Implement a menu-driven loop that allows users to perform actions like adding menu items,
placing orders, making reservations, generating bills, viewing the menu, viewing reservations, and
exiting the system.
**Important Notes:**
- Display relevant prompts and messages to guide the user throughout the process.
- Handle input exceptions properly and ensure the program runs without any errors.
- Provide clear comments for each step of the code to explain its functionality.
- Test the program with various scenarios and verify the correctness of the results.
**Sample Output:**
```
Welcome to Advanced Restaurant Management System!
1. Add Menu Item
2. Place Order
3. Make Reservation
4. Generate Bill
5. View Menu
6. View Reservations
7. Exit
Please enter your choice: 2
Available Menu Items:
1. Burger - $10.99
2. Pasta - $12.50
3. Salad - $7.95
Enter the ID of the menu item you want to order: 1
Enter the quantity: 2
Item added to the order.
Please enter your choice: 3
Enter your name: John Doe
Enter your contact number: 123-456-7890
Enter reservation date (YYYY-MM-DD): 2023-08-15
Enter number of guests: 4
Reservation confirmed! Your reservation ID is 101.
Please enter your choice: 4
Enter reservation ID: 101
Total Bill for Reservation ID 101:
Burger (x2) - $21.98
Please enter your choice: 7
Thank you for using Advanced Restaurant Management System!
```
import java.io.*;
import java.util.*;
class MenuItem {
private int id;
private String name;
private String description;
private double price;
public MenuItem(int id, String name, String description, double price) {
this.id = id;
this.name = name;
this.description = description;
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
}
class Menu {
private ArrayDeque<MenuItem> menuItems;
public Menu() {
menuItems = new ArrayDeque<>();
}
public void addItem(MenuItem item) {
menuItems.add(item);
}
public ArrayDeque<MenuItem> getMenuItems() {
return menuItems;
}
public void displayMenu() {
System.out.println("\nAvailable Menu Items:");
for (MenuItem item : menuItems) {
System.out.println(item.getId() + ". " + item.getName() + " - $" + item.getPrice());
}
}
}
class Order {
private ArrayDeque<MenuItem> items;
private ArrayDeque<Integer> quantities;
public Order() {
items = new ArrayDeque<>();
quantities = new ArrayDeque<>();
}
public void addItem(MenuItem item, int quantity) {
items.add(item);
quantities.add(quantity);
}
public ArrayDeque<MenuItem> getItems() {
return items;
}
public ArrayDeque<Integer> getQuantities() {
return quantities;
}
public double calculateTotalBill() {
double total = 0;
Iterator<MenuItem> itemIterator = items.iterator();
Iterator<Integer> quantityIterator = quantities.iterator();
while (itemIterator.hasNext() && quantityIterator.hasNext()) {
MenuItem item = itemIterator.next();
int quantity = quantityIterator.next();
total += item.getPrice() * quantity;
}
return total;
}
}
class Reservation {
private int reservationID;
private String customerName;
private String contactNumber;
private String reservationDate;
private int numberOfGuests;
public Reservation(int reservationID, String customerName, String contactNumber,
String reservationDate, int numberOfGuests) {
this.reservationID = reservationID;
this.customerName = customerName;
this.contactNumber = contactNumber;
this.reservationDate = reservationDate;
this.numberOfGuests = numberOfGuests;
}
public int getReservationID() {
return reservationID;
}
public String getCustomerName() {
return customerName;
}
public String getContactNumber() {
return contactNumber;
}
public String getReservationDate() {
return reservationDate;
}
public int getNumberOfGuests() {
return numberOfGuests;
}
}
class Restaurant {
private static Menu menu;
private static ArrayDeque<Order> orders;
private static Hashtable<Integer, Reservation> reservations;
private static int reservationCounter = 101;
public static void main(String[] args) {
menu = new Menu();
orders = new ArrayDeque<>();
reservations = new Hashtable<>();
MenuItem burger = new MenuItem(1, "Burger", "Juicy beef patty with veggies", 10.99);
MenuItem pasta = new MenuItem(2, "Pasta", "Italian pasta with marinara sauce", 12.50);
MenuItem salad = new MenuItem(3, "Salad", "Fresh greens with vinaigrette dressing", 7.95);
menu.addItem(burger);
menu.addItem(pasta);
menu.addItem(salad);
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to Advanced Restaurant Management System!\n");
while (true) {
System.out.println("1. Add Menu Item");
System.out.println("2. Place Order");
System.out.println("3. Make Reservation");
System.out.println("4. Generate Bill");
System.out.println("5. View Menu");
System.out.println("6. View Reservations");
System.out.println("7. Exit");
System.out.print("\nPlease enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
// Add Menu Item
System.out.print("Enter Menu Item ID: ");
int itemId = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Menu Item Name: ");
String itemName = scanner.nextLine();
System.out.print("Enter Menu Item Description: ");
String itemDescription = scanner.nextLine();
System.out.print("Enter Menu Item Price: ");
double itemPrice = scanner.nextDouble();
menu.addItem(new MenuItem(itemId, itemName, itemDescription, itemPrice));
System.out.println("Menu Item added successfully!");
break;
case 2:
// Place Order
menu.displayMenu();
Order order = new Order();
while (true) {
System.out.print("Enter the ID of the menu item you want to order (0 to finish): ");
int selectedItemId = scanner.nextInt();
if (selectedItemId == 0) {
break;
}
MenuItem selectedMenuItem = null;
for (MenuItem menuItem : menu.getMenuItems()) {
if (menuItem.getId() == selectedItemId) {
selectedMenuItem = menuItem;
break;
}
}
if (selectedMenuItem == null) {
System.out.println("Invalid menu item ID. Please try again.");
continue;
}
System.out.print("Enter the quantity: ");
int quantity = scanner.nextInt();
order.addItem(selectedMenuItem, quantity);
System.out.println("Item added to the order.");
}
orders.add(order);
System.out.println("Order placed successfully!");
break;
case 3:
// Make Reservation
System.out.print("Enter your name: ");
String customerName = scanner.nextLine();
System.out.print("Enter your contact number: ");
String contactNumber = scanner.nextLine();
System.out.print("Enter reservation date (YYYY-MM-DD): ");
String reservationDate = scanner.nextLine();
System.out.print("Enter number of guests: ");
int numberOfGuests = scanner.nextInt();
Reservation reservation = new Reservation(reservationCounter++, customerName,
contactNumber, reservationDate, numberOfGuests);
reservations.put(reservation.getReservationID(), reservation);
System.out.println("Reservation confirmed! Your reservation ID is " +
(reservationCounter - 1) + ".");
break;
case 4:
// Generate Bill
System.out.print("Enter reservation ID: ");
int reservationId = scanner.nextInt();
double totalBill = 0;
boolean found = false;
for (Order o : orders) {
if (!o.getItems().isEmpty()) {
totalBill = o.calculateTotalBill();
found = true;
break;
}
}
if (found) {
System.out.println("\nTotal Bill for Reservation ID " + reservationId + ":");
for (Order o : orders) {
if (!o.getItems().isEmpty()) {
for (MenuItem item : o.getItems()) {
System.out.println(item.getName() + " (x" + o.getQuantities().pop() + ") - $" +
item.getPrice());
}
}
}
System.out.println("\nTotal: $" + totalBill);
} else {
System.out.println("Reservation not found or no items ordered.");
}
break;
case 5:
// View Menu
menu.displayMenu();
break;
case 6:
// View Reservations
System.out.println("\nList of Reservations:");
for (Reservation res : reservations.values()) {
System.out.println("Reservation ID: " + res.getReservationID());
System.out.println("Customer Name: " + res.getCustomerName());
System.out.println("Contact Number: " + res.getContactNumber());
System.out.println("Reservation Date: " + res.getReservationDate());
System.out.println("Number of Guests: " + res.getNumberOfGuests());
System.out.println();
}
break;
case 7:
// Exit
System.out.println("\nThank you for using Advanced Restaurant Management System!");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please select a valid option.");
}
}
}
}