// Budget Management CLI (Dart) // Filename suggestion: Shimaa Abdulhameed_251001669_question2.txt import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to Budget Manager CLI!'); while (true) { print('\nMenu:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary'); print('4. Exit'); stdout.write('Choose (1-4): '); String? choice = stdin.readLineSync(); if (choice == null) continue; if (choice == '4') { print('Goodbye!'); break; } if (choice == '1') { stdout.write('Enter income description: '); String? desc = stdin.readLineSync(); if (desc == null || desc.trim().isEmpty) { print('Description cannot be empty.'); continue; } stdout.write('Enter income amount: '); String? amtStr = stdin.readLineSync(); double? amt = amtStr != null ? double.tryParse(amtStr) : null; if (amt == null || amt < 0) { print('Please enter a valid non-negative number for amount.'); continue; } incomeList.add({'description': desc.trim(), 'amount': amt}); print('Income added.'); } else if (choice == '2') { stdout.write('Enter expense description: '); String? desc = stdin.readLineSync(); if (desc == null || desc.trim().isEmpty) { print('Description cannot be empty.'); continue; } stdout.write('Enter expense amount: '); String? amtStr = stdin.readLineSync(); double? amt = amtStr != null ? double.tryParse(amtStr) : null; if (amt == null || amt < 0) { print('Please enter a valid non-negative number for amount.'); continue; } expenseList.add({'description': desc.trim(), 'amount': amt}); print('Expense added.'); } else if (choice == '3') { double totalIncome = 0; double totalExpenses = 0; for (var entry in incomeList) { totalIncome += (entry['amount'] as double); } for (var entry in expenseList) { totalExpenses += (entry['amount'] as double); } double net = totalIncome - totalExpenses; print('\n--- Summary ---'); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net >= 0) { print('Your net profit is \$${net.toStringAsFixed(2)}'); } else { print('Your net loss is \$${(-net).toStringAsFixed(2)}'); } // Optional: Tax calculation (15% of profit) double tax = net > 0 ? (net * 0.15) : 0.0; if (tax > 0) { print('Tax to pay (15% of profit): \$${tax.toStringAsFixed(2)}'); } else { print('No tax, no profit.'); } print('----------------'); } else { print('Invalid menu choice.'); } } }