import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print('\n--- Budget Menu ---'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary'); print('4. Exit'); stdout.write('Enter your choice: '); String? bmChoice = stdin.readLineSync(); if (bmChoice == '1') { stdout.write('Enter income description: '); String desc = stdin.readLineSync() ?? ''; stdout.write('Enter amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { incomeList.add({desc: amount}); print('Income added.'); } else { print('Invalid amount.'); } } else if (bmChoice == '2') { stdout.write('Enter expense description: '); String desc = stdin.readLineSync() ?? ''; stdout.write('Enter amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { expenseList.add({desc: amount}); print('Expense added.'); } else { print('Invalid amount.'); } } else if (bmChoice == '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('\n--- Budget Summary ---'); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpense.toStringAsFixed(2)}'); if (net >= 0) { print('Net Profit: \$${net.toStringAsFixed(2)}'); double tax = net * 0.15; print('Tax to pay (15%): \$${tax.toStringAsFixed(2)}'); } else { print('Net Loss: \$${(-net).toStringAsFixed(2)}'); } } else if (bmChoice == '4') { print('Exiting Budget Management...'); return; } else { print('Invalid choice. Try again.'); } } }