Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

A Course Based Project Report on

Hotel Management System: A GUI using JAVA


SWING

ABSTRACT

The "Hotel Booking System" Java application is designed to facilitate hotel

reservations through a user-friendly graphical interface. It allows users to input

pertinent details such as name, email, contact number, room type, arrival, and

departure dates, seamlessly adding this information to a displayed table.

The application employs Java's Swing library to create an intuitive interface. Users

can input their booking information into designated text fields and confirm the details
using the "Confirm" button. Upon confirmation, the data is added to a dynamically

updating table within the interface.

The graphical layout consists of various components: text fields for input, a button

for confirmation, and a table that dynamically exhibits the entered booking

information. The "Confirm" button triggers the addition of new entries to the table

while simultaneously clearing the input fields for the next booking entry.

The primary functionalities of this application include gathering customer booking

details and displaying them in a structured table format. Its simplicity enables

effortless interaction for users interested in managing hotel reservations.

By leveraging Java's Swing framework, this system provides a visually intuitive


means for users to input booking information and visualize their reservations. The

layout, consisting of labeled input fields and a responsive table, ensures a smooth and
organized user experience throughout the hotel booking process.
TABLE OF CONTENTS
S. No Content

1 Introduction

1.1 Problem Definition

1.2 Objective

1.3 Overview

2 Source Code

3 Test Cases/Outputs

4 Conclusion

5 References
INTRODUCTION
1.1 PROBLEM DEFINITION

The program aims to create a simple hotel booking application using Java Swing. It

provides a graphical user interface (GUI) where users can input their details like

name, email, contact number, room type, arrival date, and departure date to make a

hotel booking. The entered data gets displayed in a table within the application.

1.2 OBJECTIVE

- To create a user-friendly hotel booking system*: The objective is to allow users to

enter their booking details easily through the provided text fields.

- To display entered data in a table*: The program's goal is to exhibit the booking

information in a structured format within a table.

- To clear input fields after booking confirmation*: Upon confirming the booking by

clicking the "Confirm" button, the program aims to add the entered data to the table

and clear the input fields for the next booking entry.

1.3 OVERVIEW

1. Components:

- Text fields for user input (name, email, number, room type, arrival date,

departure date).

- "Confirm" button to add the entered data to a table.

- A table to display the booking information.

- GUI layout is structured using JPanel, JTable, JScrollPane, and JFrame.


2. Functionality:

- Users input their booking details into designated text fields.

- Upon clicking the "Confirm" button, the entered data is added to the table.

- The table dynamically updates with each confirmed booking.

- Input fields are cleared after data entry to facilitate the next booking entry.

3. Main Method:

- The main method initializes the GUI by creating an instance of the

HotelBookingApp class.

4. Event Handling:

- The "Confirm" button is associated with an ActionListener that triggers the

addDataToTable() method to process and display the entered data in the table.

CHAPTER-2
SOURCE CODE

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.border.EmptyBorder;

public class HotelBookingApp {

private JTextField nameField, emailField, numberField, roomTypeField,

arrivalDateField, departureDateField;

private DefaultTableModel tableModel;

public HotelBookingApp() {

// Create components

nameField = new JTextField(20);

emailField = new JTextField(20);

numberField = new JTextField(20);

roomTypeField = new JTextField(20);

arrivalDateField = new JTextField(20);

departureDateField = new JTextField(20);


JButton confirmButton = new JButton("Confirm");

confirmButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

addDataToTable();

});

// Add a margin to the button

confirmButton.setBorder(new EmptyBorder(5, 0, 5, 0));

// Create a table to display the data

tableModel = new DefaultTableModel();

tableModel.addColumn("Name");

tableModel.addColumn("Email");

tableModel.addColumn("Number");

tableModel.addColumn("Room Type");

tableModel.addColumn("Arrival Date");

tableModel.addColumn("Departure Date");

JTable dataTable = new JTable(tableModel);

JScrollPane scrollPane = new JScrollPane(dataTable);

// Set up the layout

JPanel inputPanel = new JPanel(new GridLayout(7, 2));

inputPanel.add(new JLabel("Name:"));
inputPanel.add(nameField);

inputPanel.add(new JLabel("Email:"));

inputPanel.add(emailField);

inputPanel.add(new JLabel("Number:"));

inputPanel.add(numberField);

inputPanel.add(new JLabel("Room Type:"));

inputPanel.add(roomTypeField);

inputPanel.add(new JLabel("Arrival Date:"));

inputPanel.add(arrivalDateField);

inputPanel.add(new JLabel("Departure Date:"));

inputPanel.add(departureDateField);

inputPanel.add(confirmButton);

// Add components to the panel

JPanel mainPanel = new JPanel(new BorderLayout());

mainPanel.add(inputPanel, BorderLayout.NORTH);

mainPanel.add(scrollPane, BorderLayout.CENTER);

// Create a frame

JFrame frame = new JFrame("Hotel Booking System");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(mainPanel);

frame.setSize(600, 400);

frame.setLocationRelativeTo(null);

frame.setVisible(true);
}

private void addDataToTable() {

String name = nameField.getText();

String email = emailField.getText();

String number = numberField.getText();

String roomType = roomTypeField.getText();

String arrivalDate = arrivalDateField.getText();

String departureDate = departureDateField.getText();

// Add data to the table

tableModel.addRow(new Object[]{name, email, number, roomType, arrivalDate,

departureDate});

// Clear input fields

nameField.setText("");

emailField.setText("");

numberField.setText("");

roomTypeField.setText("");

arrivalDateField.setText("");

departureDateField.setText("");

public static void main(String[] args) {

// Run the GUI on the event dispatch thread

SwingUtilities.invokeLater(new Runnable() {
@Override

public void run() {

new HotelBookingApp();

});

CHAPTER-3

TEST CASES/ OUTPUT


CHAPTER-4
CONCLUSION

The provided code constitutes a simple Hotel Booking Application using Java's

Swing framework, facilitating user input for hotel booking details and displaying

them in a table format. This application employs various Swing components such as

JTextField, JButton, JTable, and JScrollPane to create a functional graphical user

interface (GUI) for managing hotel reservations. Let's delve into a comprehensive

conclusion discussing the code's structure, functionality, and potential improvements.

The provided code offers a fundamental foundation for a Hotel Booking Application

with a GUI using Java Swing. It enables users to input booking information and

displays it in a tabular format. However, there's ample room for enhancement to

bolster functionality, validation, and overall user experience. By incorporating

suggested improvements, this application could evolve into a more robust and user-

centric booking system, catering to diverse user needs while ensuring data accuracy

and reliability.
REFERENCES

[1]. Java for Programmers, P. J. Deitel and H. M. Deitel, 10th Edition, Pearson

Education

[2]. Thinking in Java, Bruce Eckel, Pearson Education

[3]. Understanding Object-Oriented Programming with Java, T. Budd, Pearson

Education

[4]. https://www.w3schools.com/java/java_oop.asp

[5]. https://www.tutorialspoint.com/java/index.htm

You might also like