expense tracer in java

introduction

The Expense Tracker application helps individuals monitor their personal finances. Users can input income and expenditures across various categories such as food, travel, bills, and savings. 

The system then displays daily, weekly, or monthly summaries with graphical representation using Java Swing or charts. It promotes better financial habits by making spending visible and controllable. 

The app can also include reminders for bill payments and budget planning tools. It is ideal for students, families, and anyone interested in improving financial literacy using simple but effective software.

At its core, the application allows users:

Input income and classify it (eg, salary, freelance, other sources)

Log daily expenditure under adaptable categories such as:

  • Food and food
  • Travel and transportation
  • Bills and Utilities
  • Entertainment
  • Health

Savings or investment

These entries are timidamps and stored, enabling the app to generate summary at different time periods (daily, weekly, monthly or custom range). The graphical user interface (GUI) with intuitive knowledge is designed using Java swing, and can be extended to include data visualization tools such as bar charts, pie charts and line graphs for financial trends.

 

Major functionality:

  1. Transaction -Deen Logging: Add and see income and expenses with notes and timestamps.
  2. Summary View: Get Total Income vs Total Expenditure for the selected period.
  3. Visual Report: See where the money is going using the color-coded category chart.
  4. Budget Plan: Determine the expenditure limit for categories and get alert when you provide limitations.
  5. Bill Remrator: Set the alert for the dates fixed to avoid late payment.
  6. Data management: Save, update and delete entries; Alternatively data back up.

 

Educational and practical relevance:

  1. This project displays many real world and technical concepts:
  2. Data Handling and Verification: It is accepted to ensure only valid numerical and category-based inputs.
  3. Modular design: GUI, separation of business logic and storage layers.
  4. Event-driven programming: buttons, combo boxes, and calendar selectors trigger calculations and updates.
  5. Time-based data analysis: abbreviation and filtering entries by date range.
  6. This is a practical tool and resource for learning:
  7. Students and working professionals are managing their budget.
  8. Families watching for plans and control of monthly domestic expenses.
  9. CS students learn Java Gui

steps to create expense tracer

  • Define income and expense categories.

  • Design input forms and summary dashboards.

  • Create Transaction and Category classes.

  • Implement add, edit, delete transactions.

  • Store data in files or DB.

  • Generate summary reports and charts.

  • Add budget setting and alerts.

  • Test all features.

  • Document user guide.

  • Compile for distribution.

code explanation

1. Class & Data Model

class Expense {
    String category;
    double amount;
    String date;
    // Constructor to store values
}
  • Each expense is stored in a custom object Expense

  • You store a list of these expenses using ArrayList expenseList = new ArrayList();

 2. User Interface (GUI Components)

 Top Section: Title

JLabel heading = new JLabel("Personal Expense Tracker", JLabel.CENTER);
  • Large title at the top using BorderLayout.NORTH

3. Left Panel: Input Fields (BorderLayout.WEST)

 
cbCategory = new JComboBox(...);
tfAmount = new JTextField();
tfDate = new JTextField(LocalDate.now().toString());

This section has:

  • Dropdown for category (JComboBox)

  • Amount text field (JTextField)

  • Date field pre-filled with today (LocalDate.now())

Also includes two buttons:

JButton btnAdd = new JButton("Add Expense");
JButton btnDelete = new JButton("Delete Selected");

4. Center: Expense Table

String[] columns = {"Category", "Amount", "Date"};
DefaultTableModel tableModel = new DefaultTableModel(columns, 0);
JTable expenseTable = new JTable(tableModel);
  • Displays all entered expenses in a table format

  • Each row has 3 columns: Category, Amount, Date

  • This part is scrollable (JScrollPane)

5. Bottom: Total Expense Display

JLabel lblTotal = new JLabel("Total: ₹0.0");
  • This shows the running total of all expenses added so far

  • Updates whenever you add or delete an expense

Functionality: Event Handling

 Add Expense

btnAdd.addActionListener(e -> addExpense());

When clicked:

  • Gets values from the input fields

  • Creates a new Expense object

  • Adds it to expenseList

  • Adds a row to the table

  • Updates the total

 Delete Selected

btnDelete.addActionListener(e -> deleteSelected());

When clicked:

  • Deletes the selected row in the table

  • Removes the corresponding item from expenseList

  • Updates the total amount

 Update Total

private void updateTotal() {
    double total = 0;
    for (Expense e : expenseList) {
        total += e.amount;
    }
    lblTotal.setText("Total: ₹" + total);
}
  • Loops through all the expenses

  • Sums up the amount field

  • Displays the total at the bottom

source code

				
					import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.time.LocalDate;
import java.util.ArrayList;

class Expense {
    String category;
    double amount;
    String date;

    public Expense(String category, double amount, String date) {
        this.category = category;
        this.amount = amount;
        this.date = date;
    }
}

public class ExpenseTracker extends JFrame {

    private JTextField tfAmount, tfDate;
    private JComboBox cbCategory;
    private JTable expenseTable;
    private DefaultTableModel tableModel;
    private ArrayList expenseList = new ArrayList();
    private JLabel lblTotal;

    public ExpenseTracker() {
        setTitle("Expense Tracker");
        setSize(700, 500);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setLayout(new BorderLayout());

        // Top Label
        JLabel heading = new JLabel("Personal Expense Tracker", JLabel.CENTER);
        heading.setFont(new Font("SansSerif", Font.BOLD, 22));
        heading.setForeground(new Color(0, 102, 153));
        heading.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        add(heading, BorderLayout.NORTH);

        // Input Panel
        JPanel inputPanel = new JPanel(new GridLayout(5, 2, 10, 10));
        inputPanel.setBorder(BorderFactory.createEmptyBorder(10, 30, 10, 30));
        inputPanel.setBackground(new Color(230, 245, 255));

        cbCategory = new JComboBox(new String[]{"Food", "Transport", "Bills", "Shopping", "Others"});
        tfAmount = new JTextField();
        tfDate = new JTextField(LocalDate.now().toString());

        JButton btnAdd = new JButton("Add Expense");
        JButton btnDelete = new JButton("Delete Selected");

        inputPanel.add(new JLabel("Category:"));
        inputPanel.add(cbCategory);
        inputPanel.add(new JLabel("Amount:"));
        inputPanel.add(tfAmount);
        inputPanel.add(new JLabel("Date (YYYY-MM-DD):"));
        inputPanel.add(tfDate);
        inputPanel.add(btnAdd);
        inputPanel.add(btnDelete);

        add(inputPanel, BorderLayout.WEST);

        // Table Panel
        tableModel = new DefaultTableModel(new String[]{"Category", "Amount", "Date"}, 0);
        expenseTable = new JTable(tableModel);
        JScrollPane scrollPane = new JScrollPane(expenseTable);
        add(scrollPane, BorderLayout.CENTER);

        // Bottom Panel
        JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        lblTotal = new JLabel("Total: ₹0.0");
        lblTotal.setFont(new Font("SansSerif", Font.BOLD, 16));
        bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 20));
        bottomPanel.add(lblTotal);
        add(bottomPanel, BorderLayout.SOUTH);

        // Event Listeners
        btnAdd.addActionListener(e -> addExpense());
        btnDelete.addActionListener(e -> deleteSelected());
    }

    private void addExpense() {
        String category = cbCategory.getSelectedItem().toString();
        String date = tfDate.getText().trim();
        double amount;

        try {
            amount = Double.parseDouble(tfAmount.getText().trim());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Invalid amount!", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }

        Expense exp = new Expense(category, amount, date);
        expenseList.add(exp);
        tableModel.addRow(new Object[]{category, "₹" + amount, date});
        tfAmount.setText("");
        updateTotal();
    }

    private void deleteSelected() {
        int selected = expenseTable.getSelectedRow();
        if (selected == -1) {
            JOptionPane.showMessageDialog(this, "Please select a row to delete.");
            return;
        }
        expenseList.remove(selected);
        tableModel.removeRow(selected);
        updateTotal();
    }

    private void updateTotal() {
        double total = 0;
        for (Expense e : expenseList) {
            total += e.amount;
        }
        lblTotal.setText("Total: ₹" + total);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new ExpenseTracker().setVisible(true));
    }
}

				
			

output

More java Pojects
Get Huge Discounts