import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print('\nWelcome to the Budget Management Application!'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); stdout.write('Enter your choice: '); int? choice = int.tryParse(stdin.readLineSync() ?? ''); if (choice == null) { print('Invalid input. Please enter a number from 1 to 4.'); continue; } if (choice == 1) { stdout.write('Enter income description: '); String description = stdin.readLineSync() ?? ''; stdout.write('Enter income amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount == null || amount < 0) { print('Invalid amount. Please enter a positive number.'); } else { incomeList.add({ 'description': description, 'amount': amount, }); print('Income added!'); } } else if (choice == 2) { stdout.write('Enter expense description: '); String description = stdin.readLineSync() ?? ''; stdout.write('Enter expense amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount == null || amount < 0) { print('Invalid amount. Please enter a positive number.'); } else { expenseList.add({ 'description': description, 'amount': amount, }); print('Expense added!'); } } else if (choice == 3) { double totalIncome = 0; double totalExpenses = 0; for (var income in incomeList) { totalIncome += income['amount']; } for (var expense in expenseList) { totalExpenses += expense['amount']; } double net = totalIncome - totalExpenses; double tax = net > 0 ? net * 0.15 : 0; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net >= 0) { print('Net profit: \$${net.toStringAsFixed(2)}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else { print('Net loss: \$${net.abs().toStringAsFixed(2)}'); } } else if (choice == 4) { print('Exiting the application. Goodbye!'); break; } else { print('Invalid choice. Please select from 1 to 4.'); } } }