import 'dart:io'; void main() { print('Welcome to the Budget Management Application!\n'); 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? choice = stdin.readLineSync(); switch (choice) { case '1': stdout.write('Enter income description: '); String? desc = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amtInput = stdin.readLineSync(); double? amount = double.tryParse(amtInput ?? ''); if (desc != null && desc.isNotEmpty && amount != null && amount >= 0) { incomeList.add({desc: amount}); print('Income added successfully.'); } else { print('Invalid input! Make sure description is not empty and amount is non-negative.'); } break; case '2': stdout.write('Enter expense description: '); String? expDesc = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? expAmtInput = stdin.readLineSync(); double? expAmount = double.tryParse(expAmtInput ?? ''); if (expDesc != null && expDesc.isNotEmpty && expAmount != null && expAmount >= 0) { expenseList.add({expDesc: expAmount}); print('Expense added successfully.'); } else { print('Invalid input! Make sure description is not empty and amount is non-negative.'); } break; case '3': double totalIncome = 0; for (var item in incomeList) { totalIncome += item.values.first; } double totalExpenses = 0; for (var item in expenseList) { totalExpenses += item.values.first; } double net = totalIncome - totalExpenses; print('\n--- Budget Summary ---'); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net >= 0) { print('Your net profit is \$${net.toStringAsFixed(2)}'); } else { print('Your net loss is \$${(-net).toStringAsFixed(2)}'); } double tax = net > 0 ? net * 0.15 : 0; if (tax > 0) { print('Tax to be paid (15% of profit): \$${tax.toStringAsFixed(2)}'); } break; case '4': print('Exiting... Goodbye!'); return; default: print('Invalid choice! Please try again.'); } } }