0% found this document useful (0 votes)
14 views13 pages

AJP Project .

The Car Rental System is a Java-based application utilizing AWT and Swing for a graphical user interface, enabling users to book, manage, and return rental cars. It incorporates event handling for user interactions and JDBC for database connectivity to store and retrieve car and booking information. The system includes modules for user authentication, car management, booking, payment processing, and feedback, ensuring a seamless and efficient rental experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

AJP Project .

The Car Rental System is a Java-based application utilizing AWT and Swing for a graphical user interface, enabling users to book, manage, and return rental cars. It incorporates event handling for user interactions and JDBC for database connectivity to store and retrieve car and booking information. The system includes modules for user authentication, car management, booking, payment processing, and feedback, ensuring a seamless and efficient rental experience.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Index

Sr. No. Title Page No.

1. Introduction 1

2. Diagram 3

3. Code 5

4. Output 10

5. Conclusion 11

6. References 12
Car Rental System

Introduction

The Car Rental System in Advance Java using AWT (Abstract Window Toolkit) and Swing is
a graphical application that allows users to book, manage, and return rental cars. This system
can be developed by integrating event handling, AWT/Swing components for the user interface,
and database connectivity (e.g., using JDBC) for persistent storage of data.

1. AWT and Swing for GUI:

AWT and Swing are used to design the graphical user interface.

AWT provides basic components like buttons, text fields, labels, and panels.

Swing is built on AWT, providing more sophisticated GUI components like JFrame, JButton,
JTextField, JLabel, JPanel, etc.

Components like JTable can be used to display available cars, bookings, and customer details.

2. Event Handling:

Event handling allows the program to respond to user actions, such as clicking buttons,
selecting options, or submitting forms.

In Java, event listeners like ActionListener, MouseListener, and KeyListener are used to
manage user interactions.

Each user action (e.g., clicking a "Book" button) triggers an event that invokes a specific piece
of code (event handler).

3. Database Connectivity (JDBC):

Java Database Connectivity (JDBC) is used to connect the application with a database (e.g.,
MySQL, PostgreSQL).

The database stores information such as customer data, available cars, booking records, and
payment details.

JDBC operations such as querying the database (SELECT), inserting new data (INSERT),
updating existing records (UPDATE), and deleting data (DELETE) are utilized.

1
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

System Modules:

1. User Authentication:

Login system for customers and administrators using a database (username/password).

Different roles with different access levels (admin can manage cars, customers can book cars).

2. Car Management:

Admin functionality to add, modify, and delete cars from the system.

Car details like model, price, availability status are stored in the database.

3. Booking System:

Customers can browse available cars and book them for a specific duration.

Booking details, customer information, and car status are updated in real-time.

4. Payment System:

Option to handle payments (e.g., via credit card or cash on return) and calculate the rental fee
based on the number of days.

Payment details stored in the database.

5. Return and Feedback:

After using the car, customers can return the car, and the system updates the availability status.

2
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

Data Flow Diagram

The Data Flow Diagram (DFD) for the Car Rental System provides a visual representation of
the data interactions within the application. It highlights how users interact with the system
through the GUI, how events are triggered, and how data flows to and from the database.

Components

1. User

o Represents individuals interacting with the system, including customers and


admin staff.

o Users can browse car listings, book rentals, manage accounts, and process
payments.

2. GUI

o The graphical user interface designed with AWT and Swing.

o Features forms, buttons, and menus for searching cars, booking rentals, and
viewing transaction history.

3. Event

o Actions initiated by user interactions, such as booking a car, updating user


profiles, or processing payments.

o These events trigger requests for data updates or retrievals.

3
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

4. Database

o The storage system for all car rental-related data.

o Contains information such as user profiles, car inventory, booking details, and
payment records.

o Responds to queries and updates based on user-triggered events.

Data Flow

1. User Action: A user interacts with the GUI (e.g., searching for available cars).

o Input: User data (e.g., rental dates, car type).

2. Event Generation: The interaction triggers an event.

o Output: An event request to the database (e.g., check availability of cars).

3. Database Query: The event queries the database for relevant information.

o Input: Event request (e.g., availability check).

o Output: Data retrieved (e.g., available cars, rental rates).

4. Data Display: The retrieved data is sent back to the GUI.

o Output: Updated information displayed on the GUI (e.g., list of available cars).

5. User Confirmation: The user receives feedback on their action through the GUI.

o Output: Confirmation messages (e.g., booking confirmation, error


notifications).

6. Payment Processing: If a user books a car, a payment event is triggered.

o Input: Payment details.

o Output: Payment status sent to the database.

The data flow in the Car Rental System illustrates the interaction cycle between users and the
system. Users engage with the GUI, triggering events that query the database, ensuring real-
time updates and feedback. This flow enhances user experience by making the car rental
process efficient and effective. The DFD serves as a valuable tool to visualize and understand
the workflow of the system, ensuring clarity in its operation and design.

4
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

Code

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class CarRentalSystem extends JFrame

private JTextField modelField, regNumberField;

private JTextArea displayArea;

private Connection connection;

public CarRentalSystem()

connectDatabase();

modelField = new JTextField(15);

regNumberField = new JTextField(15);

displayArea = new JTextArea(10, 30);

JButton addButton = new JButton("Add Car");

JButton displayButton = new JButton("Display Available Cars");

JButton rentButton = new JButton("Rent Car");

JButton returnButton = new JButton("Return Car");

JPanel panel = new JPanel();

panel.add(new JLabel("Car Model:"));

5
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

panel.add(modelField);

panel.add(new JLabel("Registration Number:"));

panel.add(regNumberField);

panel.add(addButton);

panel.add(rentButton);

panel.add(returnButton);

panel.add(displayButton);

panel.add(new JScrollPane(displayArea));

add(panel);

setTitle("Car Rental System");

setDefaultCloseOperation(EXIT_ON_CLOSE);

pack();

setVisible(true);

addButton.addActionListener(e -> addCar());

displayButton.addActionListener(e -> displayAvailableCars());

rentButton.addActionListener(e -> rentCar());

returnButton.addActionListener(e -> returnCar());

private void connectDatabase() {

try {

connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
"SYSTEM", "om2006");

System.out.println("Database connected!");

6
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

} catch (SQLException e) {

e.printStackTrace();

private void addCar() {

String model = modelField.getText();

String regNumber = regNumberField.getText();

try (PreparedStatement stmt = connection.prepareStatement("INSERT INTO cars (model,


registration_number, available) VALUES (?, ?, ?)")) {

stmt.setString(1, model);

stmt.setString(2, regNumber);

stmt.setInt(3, 1); // 1 means available

stmt.executeUpdate();

JOptionPane.showMessageDialog(this, "Car added successfully!");

modelField.setText("");

regNumberField.setText("");

} catch (SQLException e) {

JOptionPane.showMessageDialog(this, "Error adding car: " + e.getMessage());

private void displayAvailableCars()

displayArea.setText("");

7
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

try (Statement stmt = connection.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM cars WHERE available = 1")) {

while (rs.next()) {

displayArea.append("Model: " + rs.getString("model") + ", Registration: " +


rs.getString("registration_number") + "\n");

} catch (SQLException e) {

e.printStackTrace();

private void rentCar() {

String regNumber = regNumberField.getText();

try (PreparedStatement stmt = connection.prepareStatement("UPDATE cars SET


available = ? WHERE registration_number = ?")) {

stmt.setInt(1, 0); // 0 means not available

stmt.setString(2, regNumber);

int rowsUpdated = stmt.executeUpdate();

if (rowsUpdated > 0) {

JOptionPane.showMessageDialog(this, "Car rented successfully!");

} else {

JOptionPane.showMessageDialog(this, "Car not found or already rented.");

} catch (SQLException e) {

e.printStackTrace();

8
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

private void returnCar() {

String regNumber = regNumberField.getText();

try (PreparedStatement stmt = connection.prepareStatement("UPDATE cars SET


available = ? WHERE registration_number = ?")) {

stmt.setInt(1, 1); // 1 means available

stmt.setString(2, regNumber);

int rowsUpdated = stmt.executeUpdate();

if (rowsUpdated > 0) {

JOptionPane.showMessageDialog(this, "Car returned successfully!");

} else {

JOptionPane.showMessageDialog(this, "Car not found or already returned.");

} catch (SQLException e) {

e.printStackTrace();

public static void main(String[] args) {

SwingUtilities.invokeLater(CarRentalSystem::new);

9
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

Output

10
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

Conclusion

The Car Rental System project effectively demonstrates the integration of advanced Java
technologies, including AWT, Swing, event handling, and database connectivity, to create a
robust and user-friendly application. The Data Flow Diagram (DFD) illustrates the seamless
interaction between users, the graphical interface, and the underlying database, highlighting
the system’s efficiency in managing car rentals.

Through this project, users can effortlessly browse available cars, manage bookings, and
process payments, all while receiving real-time updates and feedback. The use of event-driven
programming ensures that the system responds dynamically to user actions, enhancing the
overall experience.

This project not only showcases the practical application of Java programming but also
emphasizes the importance of a well-structured design in software development. By
implementing clear data flows and user interactions, the Car Rental System stands as a
comprehensive solution for managing rental operations, paving the way for further
enhancements and scalability in future iterations.

11
Soniya Gandhi Polytechnic Shrigonda
Car Rental System

Refernces

1. https://www.w3schools.com/java/
2. https://www.javatpoint.com/awt-and-swing-in-java
3. https://www.javatpoint.com/event-handling-in-java
4. https://www.geeksforgeeks.org/introduction-to-jdbc/
5. https://www.youtube.com/watch?v=7v2OnUti2eM

12
Soniya Gandhi Polytechnic Shrigonda

You might also like