// Noor Bandar ALabsi_242000818_question2. // Budget Management Application // – Question 2 import 'dart:io'; void main() { print('=============================='); print('Welcome to Budget Manager'); print('=============================='); List> incomeList = []; List> expenseList = []; bool running = true; while (running) { print('\nPlease choose an option:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary (Profit or Loss)'); print('4. Exit'); stdout.write('Enter your choice (1-4): '); String? input = stdin.readLineSync(); if (input == null) continue; int? choice = int.tryParse(input); if (choice == null || choice < 1 || choice > 4) { print('Invalid choice! Please enter a number between 1 and 4.'); continue; } if (choice == 1) { stdout.write('Enter income description: '); String? description = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount == null || amount < 0) { print('Invalid amount! Please enter a positive number.'); } else { incomeList.add({description ?? 'Unnamed Income': amount}); print('Income added successfully.'); } } else if (choice == 2) { stdout.write('Enter expense description: '); String? description = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount == null || amount < 0) { print('Invalid amount! Please enter a positive number.'); } else { expenseList.add({description ?? 'Unnamed Expense': amount}); print('Expense added successfully.'); } } else if (choice == 3) { double totalIncome = 0; double totalExpenses = 0; for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpenses += item.values.first; } double netProfit = totalIncome - totalExpenses; print('\n========= BUDGET SUMMARY ========='); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (netProfit > 0) { print('Your net profit is \$${netProfit.toStringAsFixed(2)}'); } else if (netProfit < 0) { print('Your net loss is \$${netProfit.abs().toStringAsFixed(2)}'); } else { print('You broke even – no profit or loss.'); } double tax = netProfit > 0 ? netProfit * 0.15 : 0; if (tax > 0) { print('Tax to pay (15%): \$${tax.toStringAsFixed(2)}'); } print('================================='); } else if (choice == 4) { running = false; print('\nExiting Budget Manager...'); print('Goodbye!'); } } }