Transaction statistics using Stream API
Java
Medium
streams
Task «Transaction statistics using Stream API»
Given a list of strings, each string contains information about a transaction: transaction ID, amount (double), and category (one word, may be capitalized). Using the Stream API, group transactions by category (case insensitive, convert to lowercase) and for each category output the total transaction amount rounded to two decimal places. Output the result as lines: category: amount. Sort categories alphabetically. If a category is empty, ignore such transactions.
Input Format
In the first line, an integer N (1 ≤ N ≤ 1000). Then N lines, each in the format: id amount category (separator is a space). The amount is a floating-point number, the category is a string without spaces.
Output Format
For each category with a non-zero sum, output a line: category: sum (sum with two decimal places). Categories in ascending order (lexicographically). If there are no valid transactions, output "-".
main.java