import 'dart:io'; const double taxRate = 0.15; void main() { print('Welcome to the Budget Management Application!'); List> incomeList = []; List> expenseList = []; bool running = true; while (running) { print('\nPlease choose an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); stdout.write('\nEnter your choice: '); String choice = stdin.readLineSync()?.trim() ?? ''; if (choice == '1') { stdout.write('Enter income description: '); String desc = (stdin.readLineSync() ?? '').trim(); double amount = _readAmount('Enter income amount: '); incomeList.add({desc: amount}); print('Income added!'); } else if (choice == '2') { stdout.write('Enter expense description: '); String desc = (stdin.readLineSync() ?? '').trim(); double amount = _readAmount('Enter expense amount: '); expenseList.add({desc: amount}); print('Expense added!'); } else if (choice == '3') { double totalIncome = _sumList(incomeList); double totalExpenses = _sumList(expenseList); double net = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net > 0) { print('Your net profit is \$${net.toStringAsFixed(2)}'); } else if (net < 0) { print('Your net loss is \$${(-net).toStringAsFixed(2)}'); } else { print('You are breaking even (no profit, no loss).'); } double tax = net > 0 ? net * taxRate : 0.0; if (tax > 0) { print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } } else if (choice == '4') { running = false; print('Exiting the application. Goodbye!'); } else { print('Invalid choice. Please try again.'); } } } double _readAmount(String prompt) { while (true) { stdout.write(prompt); String input = stdin.readLineSync()?.trim() ?? ''; double? value = double.tryParse(input); if (value != null && value >= 0) { return value; } print('Invalid amount! Please enter a non-negative number.'); } } double _sumList(List> list) { double total = 0.0; for (var entry in list) { if (entry.values.isNotEmpty) { total += entry.values.first; } } return total; }