import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; const double taxRate = 0.15; bool isRunning = true; print('Welcome to the Budget Management Application!'); while (isRunning) { 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() ?? 'Unknown Income'; stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount >= 0) { incomeList.add({'description': description, 'amount': amount}); print('Income added!'); } else { print('Invalid amount. Income must be a non-negative number.'); } } else if (choice == '2') { stdout.write('Enter expense description: '); String description = stdin.readLineSync() ?? 'Unknown Expense'; stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount >= 0) { expenseList.add({'description': description, 'amount': amount}); print('Expense added!'); } else { print('Invalid amount. Expense must be a non-negative number.'); } } 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 netAmount = totalIncome - totalExpenses; double tax = netAmount > 0 ? netAmount * taxRate : 0; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (netAmount > 0) { print('Your net profit is \$${netAmount.toStringAsFixed(2)}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (netAmount < 0) { print('Your net loss is \$${netAmount.abs().toStringAsFixed(2)}'); } else { print('You broke even. No profit and no loss.'); } } else if (choice == '4') { print('Exiting the application. Goodbye!'); isRunning = false; } else { print('Invalid choice. Please select a number from 1 to 4.'); } } }