0% found this document useful (0 votes)
7 views11 pages

JAVA Project Report

The Mini Project Report details the development of a command-line based expense tracker in Java aimed at helping users record, categorize, and analyze their expenses. The application features a simple interface for managing financial data and promotes better financial awareness. The report outlines the implementation process, software used, and potential enhancements for future versions.

Uploaded by

aryadalvi21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

JAVA Project Report

The Mini Project Report details the development of a command-line based expense tracker in Java aimed at helping users record, categorize, and analyze their expenses. The application features a simple interface for managing financial data and promotes better financial awareness. The report outlines the implementation process, software used, and potential enhancements for future versions.

Uploaded by

aryadalvi21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Mini Project Report

on
EXPENSE TRACKER

Datta Meghe College of


Engineering, Airoli

Sr.N Name Roll


o. No.
1. SHRAVAN SHAILESH 09
BHATKAR
2. SAKSHI SUBHASH BHOIR 11
3. VIDHAN VIKAS CHAVAN 15
4. ARYA MAHESH DALVI 17

Mrs.Vrushali Dharmale
(Practical guide)

2024-2025

Department of Artificial Intelligence and Data Science Engineering


Datta Meghe College of Engineering
(Affiliated to the University of Mumbai)

Aim:-
The aim of this project is to develop a command-line based expense
tracker in Java that enables users to efficiently record, categorize, and
analyze their expenses using awt library to make GUI. By providing a
simple interface for users to input and manage their financial data, the
project seeks to foster better financial awareness and control over
spending habits.

Introduction:-
In today’s fast-paced world, effective financial management is vital,
yet many struggle to accurately track their spending. This project
develops a simple expense tracker using Java to address this issue.
The application features a command-line interface that allows users to
log expenses, categorize them, and analyze spending trends. By
leveraging Java’s capabilities, the project underscores the importance
of coding and demonstrates how programming can provide practical
solutions for everyday challenges. This report details the development
process, features, and potential enhancements of the expense tracker,
highlighting its role in promoting financial awareness and responsible
spending habits.

Software Used:-
Java Development Kit (JDK), Notepad and Command Prompt.
Implementation:-
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

class Expense {
private String category;
private double amount;
private String date; // Format: DD-MM-YYYY

public Expense(String category, double amount, String date) {


this.category = category;
this.amount = amount;
this.date = date;
}

public String getCategory() {


return category;
}

public double getAmount() {


return amount;
}
public String getDate() {
return date;
}

@Override
public String toString() {
return category + "," + amount + "," + date;
}
}

class ExpenseManager {
private List<Expense> expenses = new ArrayList<>();

public void addExpense(String category, double amount, String date) {


expenses.add(new Expense(category, amount, date));
}

public List<Expense> getExpenses() {


return expenses;
}

public double calculateTotal() {


double total = 0;
for (Expense expense : expenses) {
total += expense.getAmount();
}
return total;
}

public void saveToFile() {


try (BufferedWriter writer = new BufferedWriter(new FileWriter("expenses.txt"))) {
for (Expense expense : expenses) {
writer.write(expense.toString());
writer.newLine();
}
JOptionPane.showMessageDialog(null, "Expenses saved successfully!");
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Error saving expenses: " + e.getMessage());
}
}

public void loadFromFile() {


try (BufferedReader reader = new BufferedReader(new FileReader("expenses.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
String category = parts[0];
double amount = Double.parseDouble(parts[1]);
String date = parts[2];
addExpense(category, amount, date);
}
} catch (IOException | NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error loading expenses: " + e.getMessage());
}
}

public void resetExpenses() {


expenses.clear(); // Clear the expenses list
File file = new File("expenses.txt");
if (file.exists()) {
file.delete(); // Delete the file
}
JOptionPane.showMessageDialog(null, "Expenses have been reset!");
}
}

public class ExpenseTrackerGUI {


private ExpenseManager manager;
private JTable expenseTable;
private DefaultTableModel tableModel;

public ExpenseTrackerGUI() {
manager = new ExpenseManager();
manager.loadFromFile(); // Load expenses at startup

// Create the main frame


JFrame frame = new JFrame("Expense Tracker");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setLayout(new BorderLayout());
frame.getContentPane().setBackground(Color.decode("#f0f8ff")); // Light blue background

// Create table for displaying expenses


String[] columnNames = {"Category", "Amount", "Date"};
tableModel = new DefaultTableModel(columnNames, 0);
expenseTable = new JTable(tableModel);
expenseTable.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(expenseTable);
frame.add(scrollPane, BorderLayout.CENTER);

// Create panel for input and buttons


JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.setBackground(Color.decode("#e6f7ff")); // Lighter blue for the panel
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10); // Add padding

// Input fields
JTextField categoryField = new JTextField(10);
JTextField amountField = new JTextField(10);
JTextField dateField = new JTextField(10);
gbc.gridx = 0; gbc.gridy = 0; panel.add(new JLabel("Category:"), gbc);
gbc.gridx = 1; panel.add(categoryField, gbc);
gbc.gridx = 0; gbc.gridy = 1; panel.add(new JLabel("Amount:"), gbc);
gbc.gridx = 1; panel.add(amountField, gbc);
gbc.gridx = 0; gbc.gridy = 2; panel.add(new JLabel("Date (DD-MM-YYYY):"), gbc);
gbc.gridx = 1; panel.add(dateField, gbc);

// Buttons
JButton addButton = new JButton("Add Expense");
JButton viewButton = new JButton("View Expenses");
JButton totalButton = new JButton("Total Expenses");
JButton resetButton = new JButton("Reset Expenses");
JButton exitButton = new JButton("Exit");

// Set button colors


addButton.setBackground(Color.decode("#80deea"));
viewButton.setBackground(Color.decode("#80deea"));
totalButton.setBackground(Color.decode("#80deea"));
resetButton.setBackground(Color.decode("#ffcc80")); // Orange for reset
exitButton.setBackground(Color.decode("#ff8a80"));

gbc.gridx = 0; gbc.gridy = 3; panel.add(addButton, gbc);


gbc.gridx = 1; panel.add(viewButton, gbc);
gbc.gridx = 0; gbc.gridy = 4; panel.add(totalButton, gbc);
gbc.gridx = 1; panel.add(resetButton, gbc);
gbc.gridx = 0; gbc.gridy = 5; panel.add(exitButton, gbc);

// Add action listeners


addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
String category = categoryField.getText();
double amount = Double.parseDouble(amountField.getText());
String date = dateField.getText();
manager.addExpense(category, amount, date);
JOptionPane.showMessageDialog(frame, "Expense added!");
categoryField.setText("");
amountField.setText("");
dateField.setText("");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(frame, "Invalid amount. Please enter a number.");
}
}
});

viewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateExpenseTable();
}
});

totalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
double total = manager.calculateTotal();
JOptionPane.showMessageDialog(frame, "Total expenses: Rs" + String.format("%.2f",
total));
}
});

resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
manager.resetExpenses(); // Reset the expenses
updateExpenseTable(); // Clear the table view
}
});

exitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
manager.saveToFile(); // Save expenses on exit
System.exit(0); // Close the application
}
});

frame.add(panel, BorderLayout.SOUTH);
frame.setVisible(true);
}

private void updateExpenseTable() {


tableModel.setRowCount(0); // Clear existing rows
for (Expense expense : manager.getExpenses()) {
tableModel.addRow(new Object[]{expense.getCategory(), expense.getAmount(),
expense.getDate()});
}
}

public static void main(String[] args) {


SwingUtilities.invokeLater(ExpenseTrackerGUI::new);
}
}
Output:-
Conclusion:-
The expense tracker project showcases the use of Java programming
for managing personal finances via a command-line interface and
GUI. It allows users to log expenses, categorize them, and generate
spending summaries. While it offers essential features, user feedback
highlights its effectiveness in tracking expenditures. Future
enhancements could include data persistence, improved user
interaction, and a graphical user interface. Overall, the project
exemplifies how programming can provide practical solutions for
everyday financial management.

R1 R2 R3 R4 Total Sign
(5 marks) (5 marks) (5 marks) (5 marks) (20 marks)

You might also like