import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to the Budget Management Application!'); while (true) { print('\nSelect an option:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Net Profit/Loss'); print('4. Exit'); String? choice = stdin.readLineSync(); if (choice == '1') { addIncome(incomeList); } else if (choice == '2') { addExpense(expenseList); } else if (choice == '3') { viewNetProfitOrLoss(incomeList, expenseList); } else if (choice == '4') { print('Thank you for using the Budget Management Application!'); break; } else { print('Invalid choice, please try again.'); } } } void addIncome(List> incomeList) { print('Enter income description:'); String? description = stdin.readLineSync(); print('Enter income amount:'); double? amount = _getValidAmount(); if (description != null && amount != null) { incomeList.add({description: amount}); print('Income added: $description - \$${amount}'); } } void addExpense(List> expenseList) { print('Enter expense description:'); String? description = stdin.readLineSync(); print('Enter expense amount:'); double? amount = _getValidAmount(); if (description != null && amount != null) { expenseList.add({description: amount}); print('Expense added: $description - \$${amount}'); } } void viewNetProfitOrLoss(List> incomeList, List> expenseList) { double totalIncome = incomeList.fold(0, (sum, income) => sum + income.values.first); double totalExpenses = expenseList.fold(0, (sum, expense) => sum + expense.values.first); double netProfitOrLoss = totalIncome - totalExpenses; if (netProfitOrLoss > 0) { double tax = netProfitOrLoss * 0.15; print('Your net profit is \$${netProfitOrLoss}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (netProfitOrLoss < 0) { print('Your net loss is \$${netProfitOrLoss.abs()}'); } else { print('You broke even, no profit or loss.'); } } double? _getValidAmount() { double? amount; while (true) { try { String? input = stdin.readLineSync(); amount = double.tryParse(input ?? ''); if (amount != null && amount >= 0) { break; } else { print('Please enter a valid non-negative amount.'); } } catch (e) { print('Invalid input. Please enter a valid amount.'); } } return amount; }