0% found this document useful (0 votes)
10 views6 pages

Java Project 9 Expense Generator

The document outlines a Java project for creating a simple expense tracker application that allows users to store, view, and summarize daily expenses. It covers key concepts such as Object-Oriented Programming, file handling, and Java collections. The basic console-based version includes functionalities to add expenses, view them, show total spending, and save/load data from a file.
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)
10 views6 pages

Java Project 9 Expense Generator

The document outlines a Java project for creating a simple expense tracker application that allows users to store, view, and summarize daily expenses. It covers key concepts such as Object-Oriented Programming, file handling, and Java collections. The basic console-based version includes functionalities to add expenses, view them, show total spending, and save/load data from a file.
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

✅ Java Project 9: Simple Expense Tracker 💸📊

📌 Problem Statement:

Create a Java application to track daily expenses — store, view, and summarize them.

🧠 What You'll Learn:

- Object-Oriented Programming

- File handling or database basics

- User input and data storage

- Java collections (ArrayList, HashMap)

✅ Basic Console-Based Version Using File Storage:

java

import [Link].*;

import [Link].*;

class Expense {

String category;

double amount;

String date;

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

[Link] = category;

[Link] = amount;
[Link] = date;

@Override

public String toString() {

return date + " | " + category + " | ₹" + amount;

public class ExpenseTracker {

static List<Expense> expenses = new ArrayList<>();

static final String FILE_NAME = "[Link]";

static Scanner sc = new Scanner([Link]);

public static void main(String[] args) {

loadExpenses();

while (true) {

[Link]("\n📌 Expense Tracker Menu:");

[Link]("1. Add Expense");

[Link]("2. View All Expenses");

[Link]("3. Show Total");

[Link]("4. Exit");

[Link]("Choose an option: ");


int choice = [Link]();

[Link]();

switch (choice) {

case 1 -> addExpense();

case 2 -> viewExpenses();

case 3 -> showTotal();

case 4 -> {

saveExpenses();

[Link]("✅ Data saved. Exiting...");

return;

default -> [Link]("❌ Invalid choice.");

static void addExpense() {

[Link]("Enter category: ");

String category = [Link]();

[Link]("Enter amount: ");

double amount = [Link]();

[Link]();

[Link]("Enter date (dd-mm-yyyy): ");

String date = [Link]();


[Link](new Expense(category, amount, date));

[Link]("✅ Expense added.");

static void viewExpenses() {

if ([Link]()) {

[Link]("No expenses yet.");

return;

[Link]("\n🧾 Your Expenses:");

for (Expense e : expenses) {

[Link](e);

static void showTotal() {

double total = 0;

for (Expense e : expenses) total += [Link];

[Link]("💰 Total Spent: ₹" + total);

static void saveExpenses() {

try (PrintWriter pw = new PrintWriter(new FileWriter(FILE_NAME))) {


for (Expense e : expenses) {

[Link]([Link] + "," + [Link] + "," + [Link]);

} catch (IOException e) {

[Link]("❌ Error saving file.");

static void loadExpenses() {

try (Scanner fileScanner = new Scanner(new File(FILE_NAME))) {

while ([Link]()) {

String[] data = [Link]().split(",");

if ([Link] == 3) {

[Link](new Expense(data[0], [Link](data[1]), data[2]));

} catch (FileNotFoundException e) {

// File not found, start fresh

💡 Bonus Ideas:

- Add monthly filtering


- Build a GUI with JavaFX

- Save data in SQLite/MySQL

React ❤ if you're ready for the next Java project

Java Projects Series: [Link]

You might also like