import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print(" Welcome to the Budget Management System!"); while (true) { print("\nChoose an option:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); stdout.write("Enter your choice (1-4): "); String? choice = stdin.readLineSync(); if (choice == '1') { addEntry(incomeList, isIncome: true); } else if (choice == '2') { addEntry(expenseList, isIncome: false); } else if (choice == '3') { viewSummary(incomeList, expenseList); } else if (choice == '4') { print(" Exiting the program. Goodbye!"); break; } else { print(" Invalid choice. Please enter a number between 1 and 4."); } } } void addEntry(List> list, {required bool isIncome}) { stdout.write("Enter ${isIncome ? 'income' : 'expense'} description: "); String? description = stdin.readLineSync(); stdout.write("Enter amount: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount == null || amount < 0) { print(" Invalid amount. Please enter a positive number."); return; } list.add({description ?? 'Unnamed': amount}); print(" ${isIncome ? 'Income' : 'Expense'} added successfully."); } void viewSummary(List> incomeList, List> expenseList) { double totalIncome = incomeList.fold(0, (sum, item) => sum + item.values.first); double totalExpenses = expenseList.fold(0, (sum, item) => sum + item.values.first); double net = totalIncome - totalExpenses; print("\n Budget Summary:"); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (net > 0) { double tax = net * 0.15; print("Your net profit is \$${net.toStringAsFixed(2)}"); print(" Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } else if (net < 0) { print("Your net loss is \$${(-net).toStringAsFixed(2)}"); } else { print("You broke even. No profit, no loss."); } }