Skip to content

HamDean/expense-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expense Tracker

A simple command-line application built in Java for managing personal expenses. It allows users to add, list, update, delete, and summarize expenses, with data persisted to a local file using serialization.

Features

  • Add new expenses with description and amount.
  • List all expenses in a formatted table.
  • Update an expense's description or amount by ID.
  • Delete (or remove) an expense by ID.
  • View a summary of total expenses, formatted as US currency.
  • Persistent storage of expenses in a local file (expenses.dat).

Requirements

  • Java 8 or higher (uses features like streams and LocalDate).
  • A Java compiler (e.g., javac) and runtime (e.g., java).

Installation

  1. Clone the repository:

    git clone https://github.com/HamDean/expense-tracker.git
    
  2. Navigate to the project directory:

    cd expense-tracker
    
  3. Compile the source files:

    javac src/*.java
    

Usage

Run the application from the comand line using commands.

Commands are provided as the first argument, followed by options in the format --key value.

Available Commands

  • add: Add a new expense.

    java -cp src Main add --description "Lunch" --amount 15.50
    
  • list: Display all expenses in a table format.

    java -cp src Main list
    
  • update: Update an existing expense by ID (can update description and/or amount).

    java -cp src Main update --id 1 --description "Dinner" --amount 20.00
    
  • remove or delete: Delete an expense by ID.

    java -cp src Main remove --id 1
    

    (Both "remove" and "delete" perform the same action.)

  • summary: Show the total expenses summary.

    java -cp src Main summary
    

Expenses are stored in src/expenses.dat. If the file doesn't exist, it will be created on the first save. Note that this is a binary file using Java serialization.

Project Structure

  • src/
    • Main.java: Entry point of the application.
    • Expense.java: Represents an individual expense with ID, description, amount, and date.
    • ExpensesManager.java: Manages the list of expenses (add, update, delete, summary, print).
    • CommandHandler.java: Handles command-line inputs and executes actions.
    • CommandParser.java: Parses command-line arguments into commands and parameters.
    • ExpenseStorage.java: Handles saving and loading expenses to/from a file.
    • expenses.dat: (Generated) Binary file for storing expenses.

Contributing

Contributions are welcome! Feel free to submit pull requests for bug fixes, improvements, or new features.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -am 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.

Notes

  • The application uses Java's built-in serialization for persistence, which is simple but not suitable for large-scale or secure applications.
  • Dates are automatically set to the current date when adding expenses.
  • Error handling is basic; invalid commands or parameters will throw exceptions.
  • For production use, consider adding more robust error handling, validation, or a database instead of file serialization.

If you encounter issues or have suggestions, open an issue on GitHub!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages