// Budget Management CLI - Dart // Save this file as question2.txt import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to Budget Management CLI'); while (true) { print('\nMenu:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary'); print('4. Exit'); stdout.write('Enter choice (1-4): '); String? choice = stdin.readLineSync(); if (choice == null) continue; if (choice == '4') { print('Exiting Budget Management CLI. 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 (positive number): '); String? amtStr = stdin.readLineSync(); double? amt = double.tryParse(amtStr ?? ''); if (amt == null || amt < 0) { print('Invalid amount. Please enter a non-negative number.'); continue; } incomeList.add({'desc': desc.trim(), 'amount': amt}); print('Income added: ${desc.trim()} - \$${amt.toStringAsFixed(2)}'); } 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 (positive number): '); String? amtStr = stdin.readLineSync(); double? amt = double.tryParse(amtStr ?? ''); if (amt == null || amt < 0) { print('Invalid amount. Please enter a non-negative number.'); continue; } expenseList.add({'desc': desc.trim(), 'amount': amt}); print('Expense added: ${desc.trim()} - \$${amt.toStringAsFixed(2)}'); } else if (choice == '3') { double totalIncome = 0.0; double totalExpenses = 0.0; if (incomeList.isEmpty && expenseList.isEmpty) { print('No income or expense records yet.'); } else { print('\n--- Income ---'); for (var item in incomeList) { totalIncome += (item['amount'] as double); print('${item['desc']} : \$${(item['amount'] as double).toStringAsFixed(2)}'); } print('\n--- Expenses ---'); for (var item in expenseList) { totalExpenses += (item['amount'] as double); print('${item['desc']} : \$${(item['amount'] as double).toStringAsFixed(2)}'); } double net = totalIncome - totalExpenses; if (net >= 0) { print('\nYour net profit is \$${net.toStringAsFixed(2)}'); } else { print('\nYour net loss is \$${net.abs().toStringAsFixed(2)}'); } 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).'); } } } else { print('Invalid choice. Please select 1-4.'); } } }