[go: up one dir, main page]

0% found this document useful (0 votes)
29 views7 pages

Resevation System

The document describes an object-oriented restaurant reservation system project built in Java. The system allows users to make reservations, select from a menu, and view their total bill. It uses classes like Reservation, MenuItem, and ReservationSystem and OOP principles like abstraction, encapsulation, inheritance and polymorphism.

Uploaded by

aliroomanq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

Resevation System

The document describes an object-oriented restaurant reservation system project built in Java. The system allows users to make reservations, select from a menu, and view their total bill. It uses classes like Reservation, MenuItem, and ReservationSystem and OOP principles like abstraction, encapsulation, inheritance and polymorphism.

Uploaded by

aliroomanq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

OOP Project

Project
Event Reservation System
Group Members
Abdul Moiz(23TL08)
Nishal Ali(23TL14)
Project Report: Restaurant Reservation
System
Introduction
The Restaurant Reservation System is a Java-based application developed to manage reservations
for various dining occasions, including standard dining experiences and extraordinary events like
birthdays. This system is designed to highlight the application of Object-Oriented Programming
(OOP) principles such as abstraction, encapsulation, inheritance, and polymorphism. The system
allows users to make reservations, select from a menu of food items, and calculate their total bill
based on their selections.

System Architecture
The system is composed of several Java classes, each serving a distinct role within the application.
Below is an overview of these classes and their functionalities.

Classes Overview

1. Reservation (Abstract Class)

 Purpose: Serves as a blueprint for all reservation types.


 Key Features:
 Abstract methods for booking and canceling reservations, allowing for different
implementations in subclasses.
 Encapsulation of common reservation properties such as date, time, and party size.

2. StandardReservation and BirthdayReservation (Subclasses)

 Purpose: Represent specific types of reservations.


 Key Features:
 Inheritance from the Reservation class.
 Polymorphic behavior through overridden methods for booking and canceling
reservations.
 Additional property in BirthdayReservation to store the name of the birthday person.
import java.time.LocalDateTime;
public class StandardReservation extends Reservation {
public StandardReservation(LocalDateTime reservationDateTime, int partySize) {
super(reservationDateTime, partySize);
}
@Override
public String book() {
return "Standard Reservation booked for " + getPartySize() + " people.";
}
@Override
public String cancel() {
return "Standard Reservation canceled.";
}
}
Birthday class:
import java.time.LocalDateTime;
public class BirthdayReservation extends Reservation {
private String birthdayPerson;
public BirthdayReservation(LocalDateTime reservationDateTime, int partySize,
String birthdayPerson) {
super(reservationDateTime, partySize);
this.birthdayPerson = birthdayPerson;
}
public String getBirthdayPerson() {
return birthdayPerson;
}
public void setBirthdayPerson(String birthdayPerson) {
this.birthdayPerson = birthdayPerson;
}
@Override
public String book() {
return "Birthday Reservation booked for " + getPartySize() + " people.
Celebrating " + birthdayPerson + "'s birthday!";
}
@Override
public String cancel() {
return "Birthday Reservation canceled for " + birthdayPerson + ".";
}
}

// Additional classes like AnniversaryReservation can be added following a similar


pattern.

3. MenuItem

 Purpose: Represents an item on the restaurant's menu.


 Key Features:
 Encapsulation of menu item properties such as name and price.
public class MenuItem {
private String name;
private double price;
public MenuItem(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
@Override
public String toString() {
return name + ": $" + String.format("%.2f", price);
}
}

4. ReservationSystem (Main Class)


 Purpose: Orchestrates the user interaction and reservation process.
 Key Features:
 Initialization of the menu with various items.
 Processing of user input for making reservations and ordering from the menu.
 Calculation and display of the total bill based on user selections.
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ReservationSystem {


private static List<MenuItem> menu = new ArrayList<>();
private static double totalBill = 0;
private static Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {


System.out.println("Welcome to the Restaurant Reservation System");
System.out.println("Type of reservation (1-Standard, 2-Birthday):");
int reservationType = Integer.parseInt(scanner.nextLine());

Reservation reservation;
if (reservationType == 2) {
reservation = makeBirthdayReservation();
} else {
// For demonstration, we use standard reservation with predetermined
details
reservation = new StandardReservation(LocalDateTime.now().plusDays(1),
4);
}
System.out.println(reservation.book());

initializeMenu();
System.out.println("\nMenu:");
displayMenu();
System.out.println("Enter the numbers of the items you'd like to order,
separated by space (e.g., 1 3 4). Press enter when done:");
String input = scanner.nextLine();
processOrder(input.split(" "));
System.out.println("Total Bill: $" + String.format("%.2f", totalBill));
}

private static BirthdayReservation makeBirthdayReservation() {


System.out.println("Enter the date and time for the reservation (yyyy-MM-dd
HH:mm):");
String dateTimeStr = scanner.nextLine();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd
HH:mm");
LocalDateTime reservationDateTime = LocalDateTime.parse(dateTimeStr,
formatter);

System.out.println("Enter the party size:");


int partySize = Integer.parseInt(scanner.nextLine());

System.out.println("Enter the name of the person celebrating a birthday:");


String birthdayPerson = scanner.nextLine();

return new BirthdayReservation(reservationDateTime, partySize,


birthdayPerson);
}

private static void initializeMenu() {


menu.add(new MenuItem("Pasta", 15.99));
menu.add(new MenuItem("Steak", 24.99));
menu.add(new MenuItem("Salad", 9.99));
menu.add(new MenuItem("Chicken Parmesan", 18.99));
menu.add(new MenuItem("Vegetarian Pizza", 14.99));
menu.add(new MenuItem("Burger", 11.99));
menu.add(new MenuItem("Sushi Platter", 22.99));
menu.add(new MenuItem("Lobster Roll", 19.99));
menu.add(new MenuItem("Vegan Curry", 13.99));
menu.add(new MenuItem("Tacos", 12.99));
menu.add(new MenuItem("Risotto", 16.99));
menu.add(new MenuItem("Grilled Salmon", 21.99));
menu.add(new MenuItem("Peking Duck", 23.99));
menu.add(new MenuItem("Tomato Soup", 7.99));
menu.add(new MenuItem("Caesar Salad", 8.99));
menu.add(new MenuItem("Beef Stroganoff", 17.99));
menu.add(new MenuItem("Falafel Wrap", 10.99));
menu.add(new MenuItem("Mushroom Risotto", 15.49));
menu.add(new MenuItem("Quiche Lorraine", 12.49));
menu.add(new MenuItem("Apple Pie", 6.99));
menu.add(new MenuItem("Chocolate Cake", 7.49)); }

private static void displayMenu() {


for (int i = 0; i < menu.size(); i++) {
System.out.println((i + 1) + ". " + menu.get(i));
}
}

private static void processOrder(String[] itemNumbers) {


for (String itemNumberStr : itemNumbers) {
int itemNumber;
try {
itemNumber = Integer.parseInt(itemNumberStr);
addToBill(itemNumber);
} catch (NumberFormatException e) {
System.out.println("Invalid input: " + itemNumberStr + ". Please
enter numbers only.");
}
}
}

private static void addToBill(int itemNumber) {


if (itemNumber > 0 && itemNumber <= menu.size()) {
MenuItem item = menu.get(itemNumber - 1);
totalBill += item.getPrice();
System.out.println(item.getName() + " added to the bill.");
} else {
System.out.println("Invalid item selection: " + itemNumber);
}
}
}

Implementation Details
The project is implemented in Java, utilizing standard libraries for handling date and time
(java.time.LocalDateTime), user input (java.util.Scanner), and collection types (java.util.List and
java.util.ArrayList). The application follows a console-based interface for simplicity, with user
interactions managed through textual input and output.
Key Algorithms and Methods

 Menu Initialization: The menu is initialized with a predefined list of MenuItem objects, each
representing a dish offered by the restaurant.
 User Input Processing: User input is gathered using a Scanner object, allowing users to
specify their reservation details and select menu items.
 Reservation Handling: Depending on the user's choice, the application creates either a
StandardReservation or a BirthdayReservation object and invokes its booking method.
 Bill Calculation: The total bill is calculated by summing the prices of the user-selected
menu items.

User Interface
The user interface is console-based, with prompts guiding the user through the reservation and
ordering process. The interface allows for the selection of the reservation type, input of reservation
details, selection of menu items, and displays the total bill.

Output:
Conclusion
The Restaurant Reservation System effectively demonstrates the use of OOP principles to create a
modular and extendable application for managing restaurant reservations. The system provides a
simple yet functional interface for users to make reservations, select food items, and view their
total bill, highlighting the power of Java in developing real-world applications.

You might also like