import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print("\n========= Income & Expense Manager ========="); print("1. ➕ Add Income"); print("2. ➖ Add Expense"); print("3. 📊 View Summary"); print("4. 🚪 Exit"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); switch (choice) { case '1': addTransaction(incomeList, "Income"); break; case '2': addTransaction(expenseList, "Expense"); break; case '3': showSummary(incomeList, expenseList); break; case '4': print("👋 Exiting system... Goodbye!"); return; default: print("⚠️ Invalid choice! Please try again."); } } } void addTransaction(List> list, String type) { stdout.write("📌 Enter $type description: "); String? desc = stdin.readLineSync(); stdout.write("💰 Enter amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount == null || amount < 0) { print("❌ Invalid amount!"); return; } list.add({ 'description': desc ?? 'No description', 'amount': amount, }); print("✅ $type added successfully!"); } void showSummary(List> incomes, List> expenses) { double totalIncome = incomes.fold(0, (sum, e) => sum + e['amount']); double totalExpenses = expenses.fold(0, (sum, e) => sum + e['amount']); double net = totalIncome - totalExpenses; print("\n========= 💼 Financial Summary ========="); print("📈 Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("📉 Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); print("💰 Net Balance: \$${net.toStringAsFixed(2)}"); if (net > 0) { double tax = net * 0.15; print("💸 Tax (15%): \$${tax.toStringAsFixed(2)}"); } else if (net < 0) { print("🔴 You are in deficit!"); } else { print("⚖️ Balanced budget — no profit or loss."); } }