Introduction
Personal finance apps are mostly data analysis: group by month, sum by category, compare with a budget. This tracker does all of that with Collectors.groupingBy, EnumMap and YearMonth, and shows how much a few stream pipelines can replace.
Problem statement
Objectives
- Use YearMonth, LocalDate and DateTimeFormatter
- Aggregate with groupingBy, summingLong and EnumMap
- Implement threshold alerts
- Present trends with bars and percentage changes
Features
- Seven categories as an enum
- Budgets with 80% and over-budget alerts
- Monthly report, top N, category shares
- Trend chart with month-on-month change
Concepts demonstrated
- Aggregation
- Date handling
- Budget alerts
- Data analysis with streams
- Enum-keyed maps
System architecture
Expense is a record with a derived month(). Expenses live in a list and budgets in an EnumMap<Category, Long>. After each add, alertIfOverBudget sums that category's spending for the expense's month. month filters by YearMonth, groups by category into an EnumMap (preserving enum order) and uses lengthOfMonth() for the daily average. trend groups by month into a TreeMap so months print in order, and scales bars to the largest month.
Folder structure
Complete source code
src/Main.java
What each file does
- src/Main.java
- The Category enum and Expense record, budget alerts, and the monthly, top, category and trend reports.
How to run it
Compile
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
budget food 6000 budget shopping 3000 add 2026-09-01 rent 15000 September rent add 2026-09-03 food 1250.50 Groceries add 2026-09-12 travel 640 Metro card add 2026-09-20 food 2100 Restaurant add 2026-09-28 bills 1830 Electricity add 2026-10-01 rent 15000 October rent add 2026-10-04 food 2400 Groceries add 2026-10-10 shopping 2600 Shoes add 2026-10-15 food 2600 Birthday dinner add 2026-10-18 shopping 899 T-shirt add 2026-10-22 health 750 Pharmacy add 2026-10-25 food 1300 Groceries add 2026-11-02 rent 15000 November rent add 2026-11-05 travel 4200 Train tickets add 2026-11-31 food 100 Bad date add 2026-11-08 fun 500 Movies add 2026-11-09 food -20 Refund month 2026-10 month 2026-11 top 3 categories trend quit
Testing
- Run with
tests/sample-input.txtand compare withtests/expected-output.txt. - October food spending reaches 83% after the birthday dinner and goes over budget (₹6,300 vs ₹6,000) after the last groceries.
- 2026-11-31 is rejected as an invalid date.
- The trend shows October up 22.7% on September and November down 24.9%.
Common errors
Months appear in random order
Group into a TreeMap (pass TreeMap::new to groupingBy) so YearMonth keys are sorted.
Average per day is wrong for February
Use YearMonth.lengthOfMonth() instead of assuming 30 days.
Possible improvements
- Import bank statements from CSV
- Support recurring expenses
- Save data to a JSON file
Additional challenges
- 1Forecast next month's spending from the last three months.
- 2Add income and show monthly savings.
- 3Show spending by day of week.
Built and tested it yourself? Mark it to update your dashboard.