0% found this document useful (0 votes)
2 views

Bill_Generator_Mini_Project_Report

The Bill Generator Application is a Java-based software that automates the bill generation process for small businesses and individual users, utilizing the Swing framework for a user-friendly GUI. It addresses inefficiencies and errors associated with manual billing by allowing users to select items, specify quantities, and calculate total costs with minimal input. The application retrieves item data from a database and features multiple modules including a home page, bill page, and summary page for a streamlined billing experience.

Uploaded by

fattealimustufa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Bill_Generator_Mini_Project_Report

The Bill Generator Application is a Java-based software that automates the bill generation process for small businesses and individual users, utilizing the Swing framework for a user-friendly GUI. It addresses inefficiencies and errors associated with manual billing by allowing users to select items, specify quantities, and calculate total costs with minimal input. The application retrieves item data from a database and features multiple modules including a home page, bill page, and summary page for a streamlined billing experience.

Uploaded by

fattealimustufa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Mini Project Report on Bill Generator Application

Chapter 1: Introduction
The Bill Generator Application is a user-friendly Java-based software developed using
the Swing framework. It simplifies the process of generating bills by allowing users to
select items, specify quantities, and calculate the total cost. The system is designed to
automate manual billing processes, making it efficient for small businesses or individual
users. The application retrieves item data from a database and presents it in a graphical
user interface (GUI), making it easier for non-technical users to generate and save bills.

This project addresses the common challenges of manual bill creation, such as human
errors in calculations, time consumption, and data entry. By utilizing Java's robust Swing
library and database connectivity, the application ensures reliable and accurate bill
generation.

Chapter 2: Problem Definition


Many small businesses rely on manual methods to create bills, leading to inefficiencies
and potential errors in calculations. This process often involves manual selection of
items, calculation of prices based on quantity, and generating a final bill. This traditional
approach can be time-consuming and prone to mistakes, especially when dealing with
multiple items. The Bill Generator Application is designed to automate these tasks,
streamlining the bill generation process by retrieving item data from a database and
calculating the total bill, including quantities and prices, with minimal user input.

Chapter 3: Modules
3.1 Home Page (HomePage.java)
The Home Page is the introductory screen of the application. It displays a welcome
message and includes a button that allows users to navigate to the bill generation screen.

Purpose: Serve as the entry point for users.

Features: Welcome message displayed at the center. Button to navigate to the bill
generation page.

Page 1
3.2 Bill Page (BillPage.java)
The Bill Page is the core component of the application where users can select items,
specify quantities, and see the calculated price. This page displays a table that
dynamically updates as the user adds items.

Purpose: Enable users to select items, specify quantities, and calculate the total price.

Features: Dropdown menus for item selection and quantity. Automatic price update based
on the selected item. Button to generate and save the final bill to a text file.

3.3 Summary Page (SummaryPage.java)


The Summary Page provides a breakdown of the selected items and the total bill amount.
It also includes an option to return to the home page.

Purpose: Display a summary of the final bill.

Features: Text area showing selected items and their corresponding prices. Button to
navigate back to the Home Page.

Page 2
Chapter 4: Database
Database Screenshot

Page 3
Chapter 5: Implementation (Complete Source Code)
5.1 BillGeneratorApp.java
package billgeneratorapp;

import javax.swing.*;

public class BillGeneratorApp {

public static void main(String[] args) {

SwingUtilities.invokeLater(() -> {

JFrame frame = new MainFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

});

5.2 BillPage.java
package billgeneratorapp;

Page 4
import javax.swing.*;

import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.sql.*;

import java.util.ArrayList;

import java.util.List;

class BillPage extends JPanel {

private JComboBox<String> itemComboBox;

private JComboBox<Integer> quantityComboBox;

private JTextField priceField;

private JTable itemTable;

private DefaultTableModel tableModel;

private MainFrame mainFrame;

private List<Double> itemPrices = new ArrayList<>();

public BillPage(MainFrame mainFrame) {

this.mainFrame = mainFrame;

setLayout(new BorderLayout());

Page 5
setBackground(new Color(255, 250, 205)); // Lemon Chiffon background

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

inputPanel.add(new JLabel("Select Item:"));

itemComboBox = new JComboBox<>();

fetchItems();

itemComboBox.addActionListener(e -> updatePrice());

inputPanel.add(itemComboBox);

inputPanel.add(new JLabel("Select Quantity:"));

Integer[] quantities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

quantityComboBox = new JComboBox<>(quantities);

inputPanel.add(quantityComboBox);

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

priceField = new JTextField();

priceField.setEditable(false); // Make it read-only

inputPanel.add(priceField);

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

addButton.setBackground(new Color(100, 149, 237)); // Cornflower blue button

addButton.setForeground(Color.WHITE);

addButton.setFont(new Font("Arial", Font.BOLD, 14));

addButton.addActionListener(new AddItemAction());

Page 6
inputPanel.add(addButton);

JButton generateButton = new JButton("Generate Bill");

generateButton.setBackground(new Color(100, 149, 237)); // Cornflower blue button

generateButton.setForeground(Color.WHITE);

generateButton.setFont(new Font("Arial", Font.BOLD, 14));

generateButton.addActionListener(new GenerateBillAction());

inputPanel.add(generateButton);

add(inputPanel, BorderLayout.NORTH);

String[] columnNames = {"Item", "Quantity", "Price", "Total"};

tableModel = new DefaultTableModel(columnNames, 0);

itemTable = new JTable(tableModel);

add(new JScrollPane(itemTable), BorderLayout.CENTER);

private void fetchItems() {

String url = "jdbc:mysql://127.0.0.1:3306/item_manager";

String user = "root";

String password = "";

try (Connection conn = DriverManager.getConnection(url, user, password);

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("SELECT item_name, amount FROM items")) {

Page 7
while (rs.next()) {

String itemName = rs.getString("item_name");

double itemAmount = rs.getDouble("amount");

itemComboBox.addItem(itemName);

itemPrices.add(itemAmount);

} catch (SQLException e) {

JOptionPane.showMessageDialog(mainFrame, "Error fetching items: " +


e.getMessage());

private void updatePrice() {

int selectedIndex = itemComboBox.getSelectedIndex();

if (selectedIndex >= 0 && selectedIndex < itemPrices.size()) {

double price = itemPrices.get(selectedIndex);

priceField.setText(String.valueOf(price));

private class AddItemAction implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

String selectedItem = (String) itemComboBox.getSelectedItem();

Page 8
int quantity = (Integer) quantityComboBox.getSelectedItem();

double price;

try {

price = Double.parseDouble(priceField.getText());

} catch (NumberFormatException ex) {

JOptionPane.showMessageDialog(mainFrame, "Invalid price. Please enter a number.");

return;

double total = quantity * price;

tableModel.addRow(new Object[]{selectedItem, quantity, price, total});

private class GenerateBillAction implements ActionListener {

@Override

public void actionPerformed(ActionEvent e) {

StringBuilder billContent = new StringBuilder();

double grandTotal = 0;

for (int i = 0; i < tableModel.getRowCount(); i++) {

String item = (String) tableModel.getValueAt(i, 0);

int quantity = (Integer) tableModel.getValueAt(i, 1);

double price = (Double) tableModel.getValueAt(i, 2);

Page 9
double total = (Double) tableModel.getValueAt(i, 3);

grandTotal += total;

billContent.append(String.format("%s - Quantity: %d, Price: %.2f, Total: %.2f%n",

item, quantity, price, total));

billContent.append(String.format("Grand Total: %.2f%n", grandTotal));

try (BufferedWriter writer = new BufferedWriter(new FileWriter("bill.txt"))) {

writer.write(billContent.toString());

JOptionPane.showMessageDialog(mainFrame, "Bill generated successfully: bill.txt");

} catch (IOException ex) {

JOptionPane.showMessageDialog(mainFrame, "Error generating bill: " +


ex.getMessage());

5.3 Homepage.java
package billgeneratorapp;

import javax.swing.*;

import java.awt.*;

Page 10
class HomePage extends JPanel {

public HomePage(MainFrame mainFrame) {

setLayout(new BorderLayout());

setBackground(new Color(173, 216, 230));

JLabel welcomeLabel = new JLabel("Welcome to the Bill Generator", JLabel.CENTER);

welcomeLabel.setFont(new Font("Arial", Font.BOLD, 18));

welcomeLabel.setForeground(new Color(34, 34, 34));

JButton startButton = new JButton("Generate Bill");

startButton.setBackground(new Color(100, 149, 237));

startButton.setForeground(Color.WHITE);

startButton.setFont(new Font("Arial", Font.BOLD, 14));

startButton.addActionListener(e -> mainFrame.showPage("Bill"));

add(welcomeLabel, BorderLayout.CENTER);

add(startButton, BorderLayout.SOUTH);

5.4 MainFrame.java
package billgeneratorapp;

import javax.swing.*;

import java.awt.*;

Page 11
class MainFrame extends JFrame {

public MainFrame() {

setTitle("Bill Generator");

setSize(400, 300);

setLayout(new CardLayout());

getContentPane().setBackground(new Color(240, 240, 240));

add(new HomePage(this), "Home");

add(new BillPage(this), "Bill");

add(new SummaryPage(this, "", 0, 0), "Summary");

((CardLayout) getContentPane().getLayout()).show(getContentPane(), "Home");

public void showPage(String page) {

((CardLayout) getContentPane().getLayout()).show(getContentPane(), page);

5.5 SummaryPage.java
package billgeneratorapp;

import javax.swing.*;

import java.awt.*;

class SummaryPage extends JPanel {

Page 12
public SummaryPage(MainFrame mainFrame, String item, int quantity, double total) {

setLayout(new BorderLayout());

setBackground(new Color(224, 255, 255));

JTextArea summaryArea = new JTextArea();

summaryArea.setEditable(false);

summaryArea.setFont(new Font("Arial", Font.PLAIN, 14));

summaryArea.setText("Item: " + item + "\nQuantity: " + quantity + "\nTotal Price: $" +


total);

summaryArea.setBackground(Color.WHITE);

summaryArea.setForeground(new Color(34, 34, 34));

JButton backButton = new JButton("Back to Home");

backButton.setBackground(new Color(100, 149, 237));

backButton.setForeground(Color.WHITE);

backButton.setFont(new Font("Arial", Font.BOLD, 14));

backButton.addActionListener(e -> {

mainFrame.remove(this);

mainFrame.showPage("Home");

});

add(summaryArea, BorderLayout.CENTER);

add(backButton, BorderLayout.SOUTH);

}}

Page 13
Chapter 6: Results
6.1 Step 1:

6.2 Step 2:

Page 14
6.3 Step 3:

6.4 Step 4:

Page 15
6.5 Step 5:

Chapter 7: Conclusion
The Bill Generator Application successfully simplifies the bill generation process by
automating item selection, quantity specification, and price calculation. The application is
easy to use, with an intuitive GUI and reliable database connectivity for fetching item
data. The system effectively reduces manual errors and increases efficiency, making it
ideal for small businesses or personal use.

Chapter 8: References
1. Oracle Java Swing Documentation

2. MySQL JDBC Documentation

3. Stack Overflow

Page 16

You might also like