Online Reservation System Using Java With Source Code

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:
Get Discount on Top Educational Courses
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 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 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
resume screener in python using python introduction The hiring process often begins with reviewing numerous resumes to filter out the most suitable …
expense tracer in python using GUI introduction Tracking daily expenses is a vital part of personal financial management. Whether you’re a student …
my personal diary in python using GUI introduction Keeping a personal diary in python is one of the oldest and most effective …
interview question app in python using GUI introduction In today’s rapidly evolving tech landscape, landing a job often requires more than just …
sudoko solver in python using GUI introduction Sudoku, a classic combinatorial number-placement puzzle, offers an engaging challenge that blends logic, pattern recognition, …
handwritten digit recognizer in python introduction In an era where artificial intelligence and deep learning are transforming industries, real-time visual recognition has …