#K68857. Expense Tracker
Expense Tracker
Expense Tracker
You are required to implement an Expense Tracker application. The application should support recording monthly expense transactions, adjusting them if necessary, and generating summary reports for a given month. The application will process several operations provided via standard input.
The supported operations are:
ADD date amount category
: Record a new transaction with the given date (in the format YYYY-MM-DD), amount (a floating point number) and category (a string). Each transaction is automatically assigned a unique transaction id.ADJUST id new_amount new_category
: Adjust the transaction with the given id. The transaction's amount and category should be updated; also mark this transaction as adjusted.SUMMARY month
: Summarize all transactions for the given month (format YYYY-MM), aggregating the total amount for each category. Also, list the transaction ids of all transactions that were adjusted in that month. For each summary operation, you should print one block of output as described below.
The summary output block should list each category and its total amount on separate lines in the order in which the category first appears in any transaction for that month; the block ends with a line starting with Adjustments:
followed by the list (in Python list format) of transaction ids that have been adjusted. If there are no transactions for a given month, simply output Adjustments: []
.
Note: If multiple SUMMARY operations are executed, output their results in the same order as the operations appear, separated by a blank line.
inputFormat
The first line contains an integer n, denoting the number of operations. The next n lines each contain one operation. An operation is one of the following formats:
ADD date amount category
ADJUST id new_amount new_category
SUMMARY month
All input is given via standard input (stdin).
outputFormat
For each SUMMARY operation, output a block of lines as follows:
- For each category present in transactions in that month, output a line in the format:
Category: total_amount
. - Output a final line in the format:
Adjustments: [list]
wherelist
is a Python-style list (e.g., [1, 2]) of transaction ids that were adjusted in that month. If none, output an empty list:[]
.
If there are multiple SUMMARY operations, separate each block by a blank line. All output should be printed to standard output (stdout).
## sample6
ADD 2023-01-01 1000.0 Rent
ADD 2023-01-15 150.0 Utilities
ADD 2023-01-20 200.0 Supplies
SUMMARY 2023-01
ADJUST 1 1100.0 Rent
SUMMARY 2023-01
Rent: 1000.0
Utilities: 150.0
Supplies: 200.0
Adjustments: []
Rent: 1100.0
Utilities: 150.0
Supplies: 200.0
Adjustments: [1]
</p>