Online Guest Reservation System using Java With Source Code

Online Reservation System using Java

Introduction :

Welcome to Online Reservation System using Java. This system allows you to make reservations for guests in online mode. Online reservation systems have become increasingly popular in recent years, as more and more businesses look to streamline their booking process and provide a more convenient experience for their customers. In this blog, we will discuss how to build an online reservation system using Java. The online reservation system we will build will be a simple console-based application that allows users to make, view, and cancel reservations. For businesses, online reservation systems offer a number of benefits, including increased efficiency, reduced workload, improved customer experience, and the ability to manage and monitor reservations in real-time. Overall, online reservation systems have become a vital tool for businesses in today’s digital age, providing a streamlined and convenient way for customers to make reservations while helping businesses to operate more efficiently and effectively.

Explanation :

The online reservation system we will build will be a simple console-based application that allows users to make, view, and cancel reservations. We will use the following components to build the system: Reservation Class, Reservation System Class and User Interface. We will discuss about each class and its functionality. Reservation class will represent a reservation and will have properties like name, date, and number of guests. This class consists of methods for name, ID, date etc. ‘this’ keyword is used to get reference of running class. Reservation System class will manage the reservations and will have methods for making a reservation, getting all reservations, getting a reservation by ID, and cancelling a reservation. Array list  has been used in this class to make things simple for adding reservation using ‘add’ function and deleting reservations with ‘remove’ function. User Interface will be a simple console-based interface that allows users to interact with the reservation system. For taking the inputs from user, we have used the scanner class. In while loop all the options have been mentioned as – Make a reservation, view all reservations, Cancel a reservation and Exit. Reservations can simply be made by giving information of user and calling the make reservation method. It will return output as reservation ID. Cancelling of reservation is take place by ID. It will delete reservation of given ID. Summing up all the things, OOPS and some basic java concepts are the core of this system. Happy Coding!

Source Code :

				
					import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
class Reservation {
    private int id;
    private String name;
    private String date;
    private int numberOfGuests;

    public Reservation(int id, String name, String date, int numberOfGuests) {
        this.id = id;
        this.name = name;
        this.date = date;
        this.numberOfGuests = numberOfGuests;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDate() {
        return date;
    }

    public int getNumberOfGuests() {
        return numberOfGuests;
    }
}


 class ReservationSystem {
    private List<Reservation> reservations = new ArrayList<>();
    private int nextId = 1;

    public Reservation makeReservation(String name, String date, int numberOfGuests) {
        Reservation reservation = new Reservation(nextId++, name, date, numberOfGuests);
        reservations.add(reservation);
        return reservation;
    }

    public List<Reservation> getReservations() {
        return reservations;
    }

    public Reservation getReservationById(int id) {
        for (Reservation reservation : reservations) {
            if (reservation.getId() == id) {
                return reservation;
            }
        }
        return null;
    }

    public boolean cancelReservation(int id) {
        Reservation reservation = getReservationById(id);
        if (reservation != null) {
            reservations.remove(reservation);
            return true;
        }
        return false;
    }
}


 class ReservationSystemUI {
    private ReservationSystem reservationSystem = new ReservationSystem();

    public void start() {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("1. Make a reservation");
            System.out.println("2. View all reservations");
            System.out.println("3. Cancel a reservation");
            System.out.println("4. Exit");

            int choice = scanner.nextInt();
            scanner.nextLine();

            switch (choice) {
                case 1:
                    System.out.print("Name: ");
                    String name = scanner.nextLine();
                    System.out.print("Date: ");
                    String date = scanner.nextLine();
                    System.out.print("Number of guests: ");
                    int numberOfGuests = scanner.nextInt();
                    scanner.nextLine();

                    Reservation reservation = reservationSystem.makeReservation(name, date, numberOfGuests);
                    System.out.println("Reservation made with ID " + reservation.getId());
                    break;
                case 2:
                    System.out.println("Reservations:");
                    for (Reservation r : reservationSystem.getReservations()) {
                        System.out.println(r.getId() + " - " + r.getName() + " - " + r.getDate() + " - " + r.getNumberOfGuests());
                    }
                    break;
                case 3:
                    System.out.print("Reservation ID to cancel: ");
                    int id = scanner.nextInt();
                    scanner.nextLine();

                    if (reservationSystem.cancelReservation(id)) {
                        System.out.println("Reservation canceled");
                    } else {
                        System.out.println("Reservation not found");
                    }
                    break;
                case 4:
                    return;
                default:
                    System.out.println("Invalid choice");
            }

            System.out.println();
        }
    }

    public static void main(String[] args)
    {
        ReservationSystemUI obj = new ReservationSystemUI();
        obj.start();
    }
}
				
			

Output :

Find More Projects

Bank Management System Using Python Django Introduction The Bank Management System V2.0.2 is a feature-rich online banking solution built using the Python …

Pharmacy Management System Using Python Django Introduction The Pharmacy Dispensing Management System is a robust and user-friendly software solution developed using Python …

Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …

Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …

Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …

Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …

Download 1000+ Coding Projects Code