import 'dart:io'; List> incomeEntries = []; List> expenseEntries = []; void addEntry(List> entries, String type) { stdout.write("Enter $type description: "); String description = stdin.readLineSync() ?? 'N/A'; stdout.write("Enter $type amount: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount >= 0) { entries.add({'description': description, 'amount': amount}); print("${type.substring(0, 1).toUpperCase()}${type.substring(1)} added!"); } else { print("Invalid amount. Please enter a valid non-negative number."); } } void viewSummary() { double totalIncome = incomeEntries.fold(0.0, (sum, entry) => sum + entry['amount']); double totalExpenses = expenseEntries.fold(0.0, (sum, entry) => sum + entry['amount']); double netProfit = totalIncome - totalExpenses; double tax = netProfit > 0 ? netProfit * 0.15 : 0.0; print("\n--- Financial Summary ---"); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (netProfit >= 0) { print("Net Profit: \$${netProfit.toStringAsFixed(2)}"); if (netProfit > 0) { print("Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } } else { print("Net Loss: \$${(netProfit * -1).toStringAsFixed(2)}"); } } void main() { print("Welcome to the Budget Management Application!"); while (true) { print("\nPlease choose an option:"); 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': addEntry(incomeEntries, 'income'); break; case '2': addEntry(expenseEntries, 'expense'); break; case '3': viewSummary(); break; case '4': print("Exiting the application. Goodbye!"); return; default: print("Invalid choice. Please enter a number between 1 and 4."); } } }