Project Title
Ticket Booking System in Java
1. Introduction
This project implements a simple console-based ticket booking system. It simulates the
management of a fixed number of seats (initially 10) and allows users to book tickets until the
seats are sold out. Users can exit the program by entering 0. It demonstrates basic Java concepts
such as loops, conditionals, user input handling, and variable manipulation.
2. Objectives
Demonstrate the use of Java’s Scanner for console input.
Showcase control flow using while, if–else statements.
Manage state using class variables (seats).
Develop a user-friendly loop for booking until seats are depleted or the user opts out.
3. Program Code
java
CopyEdit
import [Link].*;
public class TicketBooking {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int seats = 10;
while (true) {
[Link]("\nAvailable Seats: " + seats);
[Link]("Enter number of tickets to book (0 to exit): ");
int num = [Link]();
if (num == 0) {
[Link]("Thank you for using Ticket Booking!");
break;
} else if (num <= seats) {
seats -= num;
[Link]("Booked " + num + " ticket(s). Remaining: "
+ seats);
} else {
[Link]("Not enough seats. Try less.");
}
}
[Link]();
}
}
4. Output
vbnet
CopyEdit
Available Seats: 10
Enter number of tickets to book (0 to exit): 3
Booked 3 ticket(s). Remaining: 7
Available Seats: 7
Enter number of tickets to book (0 to exit): 0
Thank you for using Ticket Booking!
=== Code Execution Successful ===
5. Conclusion
This project successfully implements a basic ticket booking system with console interaction. It
effectively demonstrates key Java fundamentals:
Handling user input through Scanner.
Using loops and conditionals for decision-making.
Managing and updating program state.