import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to the Budget Management Application!'); while (true) { print('\nPlease choose an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); stdout.write('Enter your choice: '); String? choice = stdin.readLineSync(); if (choice == '1') { stdout.write('Enter income description: '); String? description = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); if (description != null && amountInput != null) { double? amount = double.tryParse(amountInput); if (amount != null && amount > 0) { incomeList.add({description: amount}); print('Income added!'); } else { print('Invalid amount. Please enter a positive number.'); } } } else if (choice == '2') { stdout.write('Enter expense description: '); String? description = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); if (description != null && amountInput != null) { double? amount = double.tryParse(amountInput); if (amount != null && amount > 0) { expenseList.add({description: amount}); print('Expense added!'); } else { print('Invalid amount. Please enter a positive number.'); } } } else if (choice == '3') { double totalIncome = incomeList.fold(0, (prev, element) => prev + element.values.first); double totalExpenses = expenseList.fold(0, (prev, element) => prev + element.values.first); double netProfit = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (netProfit >= 0) { print('Your net profit is \$${netProfit.toStringAsFixed(2)}'); double tax = netProfit > 0 ? netProfit * 0.15 : 0; print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else { print('Your net loss is \$${(-netProfit).toStringAsFixed(2)}'); } } else if (choice == '4') { print('Exiting the application. Goodbye!'); break; } else { print('Invalid choice. Please try again.'); } } }