import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { // Display menu options to the user print('\nChoose an action:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); String? choice = stdin.readLineSync(); switch (choice) { case '1': print('Enter income description:'); String description = stdin.readLineSync() ?? ''; print('Enter income amount:'); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount > 0) { incomeList.add({description: amount}); print('Income added.'); } else { print('Invalid amount.'); } break; case '2': print('Enter expense description:'); String description = stdin.readLineSync() ?? ''; print('Enter expense amount:'); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount > 0) { expenseList.add({description: amount}); print('Expense added.'); } else { print('Invalid 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 net = totalIncome - totalExpense; print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpense.toStringAsFixed(2)}'); print(net >= 0 ? 'Net Profit: \$${net.toStringAsFixed(2)}' : 'Net Loss: \$${net.abs().toStringAsFixed(2)}'); if (net > 0) { double tax = net * 0.15; print('Tax Due: \$${tax.toStringAsFixed(2)}'); } break; case '4': print('Goodbye!'); return; default: print('Invalid choice.'); } } }