import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print("\n=== BUDGET MANAGEMENT MENU ==="); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary (Profit / Loss)"); print("4. Exit"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); if (choice == "1") { stdout.write("Enter income description: "); String desc = stdin.readLineSync()!; stdout.write("Enter income amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount >= 0) { incomeList.add({desc: amount}); print("Income added successfully!"); } else { print("Invalid amount. Try again."); } } else if (choice == "2") { stdout.write("Enter expense description: "); String desc = stdin.readLineSync()!; stdout.write("Enter expense amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount >= 0) { expenseList.add({desc: amount}); print("Expense added successfully!"); } else { print("Invalid amount. Try again."); } } else if (choice == "3") { double totalIncome = 0; double totalExpenses = 0; for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpenses += item.values.first; } double netResult = totalIncome - totalExpenses; print("\n=== BUDGET SUMMARY ==="); print("Total Income: $totalIncome SAR"); print("Total Expenses: $totalExpenses SAR"); print(netResult >= 0 ? "Your net profit is ${netResult.toStringAsFixed(2)} SAR" : "Your net loss is ${(-netResult).toStringAsFixed(2)} SAR"); // Optional tax feature double tax = netResult > 0 ? netResult * 0.15 : 0; if (tax > 0) { print("Tax to pay (15%): ${tax.toStringAsFixed(2)} SAR"); } } else if (choice == "4") { print("Exiting program. Goodbye!"); return; } else { print("Invalid choice. Try again."); } } }