import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print("\nBudget Management"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); stdout.write("Choose an option: "); String? choice = stdin.readLineSync(); switch (choice) { case '1': stdout.write("Enter income description: "); String? desc = stdin.readLineSync(); stdout.write("Enter income amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (desc != null && amount != null && amount > 0) { incomeList.add({desc: amount}); print("Income added successfully."); } else { print("Invalid input. Please enter a valid amount."); } break; case '2': stdout.write("Enter expense description: "); String? desc = stdin.readLineSync(); stdout.write("Enter expense amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (desc != null && amount != null && amount > 0) { expenseList.add({desc: amount}); print("Expense added successfully."); } else { print("Invalid input. Please enter a valid amount."); } break; case '3': double totalIncome = incomeList.fold(0, (sum, item) => sum + item.values.first); double totalExpense = expenseList.fold(0, (sum, item) => sum + item.values.first); double netProfit = totalIncome - totalExpense; print("\n--- Budget Summary ---"); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpense.toStringAsFixed(2)}"); print("Net Profit/Loss: \$${netProfit.toStringAsFixed(2)}"); if (netProfit > 0) { double tax = netProfit * 0.15; print("Tax to Pay (15%): \$${tax.toStringAsFixed(2)}"); } print("----------------------"); break; case '4': print("Exiting Budget Management..."); return; default: print("Invalid choice. Please try again."); } } }