import 'dart:io'; void main() { print("=== Simple Budget Tracker ==="); List> income = []; List> expenses = []; bool active = true; while (active) { print("\nChoose an action:"); print("1) Record Income"); print("2) Record Expense"); print("3) Show Financial Report"); print("4) Exit"); stdout.write("Your choice: "); String? option = stdin.readLineSync(); if (option == null) continue; if (option == "1") { _record(income, true); } else if (option == "2") { _record(expenses, false); } else if (option == "3") { _report(income, expenses); } else if (option == "4") { print("Exiting... Have a great day!"); active = false; } else { print("Invalid selection."); } } } void _record(List> list, bool isIncome) { stdout.write("Enter description: "); String? desc = stdin.readLineSync(); if (desc == null || desc.isEmpty) { print("Description cannot be empty."); return; } stdout.write("Enter amount: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ""); if (amount == null || amount < 0) { print("Amount must be a positive number."); return; } list.add({desc: amount}); print("${isIncome ? "Income" : "Expense"} recorded."); } void _report(List> income, List> expenses) { double totalIncome = 0; double totalExpenses = 0; for (var item in income) { totalIncome += item.values.first; } for (var item in expenses) { totalExpenses += item.values.first; } double net = totalIncome - totalExpenses; print("\n=== Financial Report ==="); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (net > 0) { print("Net Profit: \$${net.toStringAsFixed(2)}"); // Optional tax calculation double tax = net > 0 ? net * 0.15 : 0; print("Tax (15%): \$${tax.toStringAsFixed(2)}"); print("Profit After Tax: \$${(net - tax).toStringAsFixed(2)}"); } else if (net < 0) { print("Net Loss: \$${net.abs().toStringAsFixed(2)}"); print("No tax applied."); } else { print("Break-even: No profit, no loss."); } }