Airline Reservation System Using Java With Source Code

Airline reservation system using java

Introduction:

In this project, we’ll show you how to create an Airline reservation system using java. This is a command-line user interface-based airline reservation system that allows you to check seat availability and reserve a seat if it is available. The system is designed with a switch case that gives you three options: view available seats, and reserve a seat. So, get a cup of coffee and use the airline reservation system.

Explanation :

This Command-Line User Interface (CLI)-based Airline Reservation System provides a simple and easy way for checking seat availability and reserving a seat if it is available. The system includes a simple command line interface with a switch case for executing viewing available seats and reserving a seat.

Switch Case, while loop, and Scanner class are used to build this system. The system will first present the user with the available options. View available seats, book a seat, and EXIT is available as a choice. The user must choose a useful option. The operation will be carried out as per the input choice.  The seats are stored in array seats, where 0 indicates an available seat and 1 represents a reserved seat.

Source Code :

Get Discount on Top Educational Courses

Brand NameDiscount InformationCoupon Codes Link
Educative.io20% discount on Educative courses and plans
W3Schools20% discount on W3Schools courses
KodeKloud10% discount on KodeKloud courses and plans
GeeksforGeeks30% discount on GeeksforGeeks courses
Target Test Prep20% discount on Target Test Prep
Coding Ninjas₹5000 discount on Coding Ninjas courses
Skillshare40% discount on Skillshare
DataCamp50% discount on DataCamp
365 Data Science57% discount on 365 Data Science Plans
Get SmarterFlat 20% discount on Get Smarter courses
SmartKeedaFlat 40% discount on SmartKeeda courses
StackSocial20% discount on StackSocial courses
				
					//importing required packages for program
import java.util.Scanner;

//creating class
public class airline_reservation {
    //declaring static global variables
    static int seats[] = new int[11];
    static Scanner sc = new Scanner(System.in);
    
    //creating main
    public static void main(String[] args) {
        System.out.println("Welcome to XYZ Airlines");
        //while loop to display option till the exit is called
        while (true) {
            System.out.println("Please select an option: ");
            System.out.println("1. View available seats");
            System.out.println("2. Reserve a seat");
            System.out.println("3. Exit");
            int choice = sc.nextInt();
            //use of switch case for performing operation of users's prefered choice
            switch (choice) {
                case 1://display seat
                    displaySeats();
                    break;
                case 2://reserve seat
                    reserveSeat();
                    break;
                case 3:
                    System.out.println("Thank you for using XYZ Airlines");
                    System.exit(0);
            } //end of switch case
        } //end of while loop
    } //end of main method

    //declaring method displaySeats() for display avaliable and reserved seats
    public static void displaySeats() {
        System.out.println("Seats:");
        for (int i = 1; i <= 10; i++) {
            //use of ternary operator to print if the seats are avalible or not
            System.out.println("Seat " + i + ": " + (seats[i] == 0 ? "Available" : "Reserved"));
        }
    } //end of displayseats()

    //declaring method reserveSeat()
    public static void reserveSeat() {
        System.out.println("Enter seat number to reserve: ");
        int seat = sc.nextInt();
        //if checks if the seat is avaliable or not and if the the seat is avaliable it reserves the seat else the seat will be not reserved
        if (seats[seat] == 0) {
            seats[seat] = 1;
            System.out.println("Seat " + seat + " reserved successfully");
        } else {
            System.out.println("Seat " + seat + " is already reserved");
        }
    }
}//end of class
				
			

Output :

airlines reservation system output

Find More Projects

ludo game in python using gui and thinkter introduction The “ludo game in python“ project is a simplified digital version of the …

hotel management system in python introduction The Hotel Management System is a simple, interactive GUI-based desktop application developed using Python’s Tkinter library. …

cryptography app in python using gui introduction In the digital age, data security and privacy are more important than ever. From messaging …

portfolio generator tool in python using GUI introduction In today’s digital-first world, having a personal portfolio is essential for students, job seekers, …

interactive story game in python using gui introduction The Interactive story game in python using gUI  is a visually rich, dynamic, and engaging …

maze generator using Python with Pygame Module GUI introduction In this maze generator using Python, realm of logic, problem-solving, and computer science, …

More java Pojects
Get Huge Discounts