import 'dart:io'; // Required to read user input void main() { // Welcome message print('Welcome to the Budget Management Application!'); // Lists to store income and expenses List> incomeList = []; List> expenseList = []; while (true) { // Display menu options print('\nChoose an option:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary'); print('4. Exit'); String? choice = stdin.readLineSync(); switch (choice) { case '1': // Add income print('Enter income description:'); String? desc = stdin.readLineSync(); double? amount; do { print('Enter amount (positive number only):'); String? amtInput = stdin.readLineSync(); amount = double.tryParse(amtInput ?? ''); if (amount == null || amount <= 0) { print('Invalid amount. Please try again.'); amount = null; } } while (amount == null); incomeList.add({desc ?? 'Unnamed Income': amount}); print( 'Income added: ${desc ?? "Unnamed Income"} with amount \$${amount}', ); break; case '2': // Add expense print('Enter expense description:'); String? descExp = stdin.readLineSync(); double? amountExp; do { print('Enter amount (positive number only):'); String? amtInputExp = stdin.readLineSync(); amountExp = double.tryParse(amtInputExp ?? ''); if (amountExp == null || amountExp <= 0) { print('Invalid amount. Please try again.'); amountExp = null; } } while (amountExp == null); expenseList.add({descExp ?? 'Unnamed Expense': amountExp}); print( 'Expense added: ${descExp ?? "Unnamed Expense"} with amount \$${amountExp}', ); break; case '3': // View summary double totalIncome = 0; double totalExpense = 0; for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpense += item.values.first; } double netProfit = totalIncome - totalExpense; double tax = netProfit > 0 ? netProfit * 0.15 : 0; print('\n=== Financial Summary ==='); print('Total Income: \$${totalIncome}'); print('Total Expenses: \$${totalExpense}'); if (netProfit > 0) { print('Net Profit: \$${netProfit}'); print('Tax (15%): \$${tax}'); } else if (netProfit < 0) { print('Net Loss: \$${-netProfit}'); } else { print('No profit or loss.'); } break; case '4': print('Exiting program...'); return; default: print('Invalid choice. Please try again.'); } } }