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.
- 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).
- Java 8 or higher (uses features like streams and LocalDate).
- A Java compiler (e.g.,
javac) and runtime (e.g.,java).
-
Clone the repository:
git clone https://github.com/HamDean/expense-tracker.git -
Navigate to the project directory:
cd expense-tracker -
Compile the source files:
javac src/*.java
Run the application from the comand line using commands.
Commands are provided as the first argument, followed by options in the format --key value.
-
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.
- 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.
Contributions are welcome! Feel free to submit pull requests for bug fixes, improvements, or new features.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
- 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!