import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; const double TAX_RATE = 0.15; 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? choiceInput = stdin.readLineSync(); if (choiceInput == null || choiceInput.isEmpty) { print('Invalid input. Please try again.'); continue; } int choice = int.tryParse(choiceInput) ?? 0; switch (choice) { case 1: stdout.write('Enter income description: '); String? desc = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); double amount = double.tryParse(amountInput ?? '') ?? 0.0; if (amount > 0 && desc != null && desc.isNotEmpty) { incomeList.add({'description': desc, 'amount': amount}); print('Income added!'); } else { print('Invalid amount or description. Amount must be positive.'); } break; case 2: stdout.write('Enter expense description: '); String? desc = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); double amount = double.tryParse(amountInput ?? '') ?? 0.0; if (amount > 0 && desc != null && desc.isNotEmpty) { expenseList.add({'description': desc, 'amount': amount}); print('Expense added!'); } else { print('Invalid amount or description. Amount must be positive.'); } break; case 3: double totalIncome = incomeList.fold(0.0, (sum, item) => sum + item['amount']!); double totalExpense = expenseList.fold(0.0, (sum, item) => sum + item['amount']!); double net = totalIncome - totalExpense; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpense.toStringAsFixed(2)}'); if (net > 0) { print('Net profit: \$${net.toStringAsFixed(2)}'); double tax = net * TAX_RATE; print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (net < 0) { print('Net loss: \$${(-net).toStringAsFixed(2)}'); } else { print('Net balance: \$0.00'); } break; case 4: print('Exiting the application. Goodbye!'); exit(0); default: print('Invalid choice. Please try again.'); } } }