import 'dart:io'; final List> incomeList = []; final List> expenseList = []; void main() { print('Welcome to Budget Manager!'); String? input; while (true) { showOptions(); input = stdin.readLineSync(); if (input == '1') { handleEntry(incomeList, 'income'); } else if (input == '2') { handleEntry(expenseList, 'expense'); } else if (input == '3') { summarizeBudget(); } else if (input == '4') { print('Goodbye!'); break; } else { print('Invalid option.'); } } } void showOptions() { print('\nSelect an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); stdout.write('Choice: '); } void handleEntry(List> list, String type) { stdout.write('Enter $type description: '); String? desc = stdin.readLineSync(); stdout.write('Enter $type amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { list.add({'description': desc ?? 'Unnamed', 'amount': amount}); print('$type added: ${desc ?? 'Unnamed'} - \$${amount.toStringAsFixed(2)}'); } else { print('Invalid amount.'); } } void summarizeBudget() { double totalIncome = incomeList.fold(0, (sum, item) => sum + item['amount']); double totalExpense = expenseList.fold(0, (sum, item) => sum + item['amount']); double net = totalIncome - totalExpense; print('\n--- Budget Summary ---'); print('Income: \$${totalIncome.toStringAsFixed(2)}'); print('Expenses: \$${totalExpense.toStringAsFixed(2)}'); if (net >= 0) { print('Net profit: \$${net.toStringAsFixed(2)}'); double tax = net > 0 ? net * 0.15 : 0; print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else { print('Net loss: \$${net.abs().toStringAsFixed(2)}'); } }