Question 2: Budget Management Application: Solution: import 'dart:io'; void main() { print('Welcome to the Budget Management Application!'); // Lists to store income and expenses List> incomeList = []; List> expenseList = []; // Tax rate constant const double taxRate = 0.15; // Main program loop while (true) { print('\nPlease choose an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); stdout.write('\nEnter your choice: '); String? choice = stdin.readLineSync(); switch (choice) { case '1': // Add income addTransaction(incomeList, 'income'); break; case '2': // Add expense addTransaction(expenseList, 'expense'); break; case '3': // View summary viewSummary(incomeList, expenseList, taxRate); break; case '4': // Exit program print('Exiting the application. Goodbye!'); return; default: print('Invalid choice! Please enter a number between 1 and 4.'); } } } // Function to add income or expense void addTransaction(List> list, String type) { stdout.write('Enter ${type} description: '); String? description = stdin.readLineSync(); while (true) { stdout.write('Enter ${type} amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); if (amount >= 0) { list.add({ 'description': description ?? 'Unknown', 'amount': amount }); print('${type.capitalize()} added!'); break; } else { print('Invalid amount! Please enter a positive number.'); } } catch (e) { print('Invalid input! Please enter a valid number.'); } } } // Function to view summary and calculate tax void viewSummary(List> incomeList, List> expenseList, double taxRate) { double totalIncome = calculateTotal(incomeList); double totalExpenses = calculateTotal(expenseList); double netProfit = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (netProfit >= 0) { print('Net profit: \$${netProfit.toStringAsFixed(2)}'); // Tax calculation using ternary operator double tax = netProfit > 0 ? netProfit * taxRate : 0; if (tax > 0) { print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } } else { print('Net loss: \$${(-netProfit).toStringAsFixed(2)}'); } // Display detailed lists if (incomeList.isNotEmpty) { print('\nIncome Details:'); for (var income in incomeList) { print('- ${income['description']}: \$${income['amount'].toStringAsFixed(2)}'); } } if (expenseList.isNotEmpty) { print('\nExpense Details:'); for (var expense in expenseList) { print('- ${expense['description']}: \$${expense['amount'].toStringAsFixed(2)}'); } } } // Function to calculate total of a list double calculateTotal(List> list) { double total = 0; for (var item in list) { total += item['amount']; } return total; } // Extension method to capitalize first letter extension StringExtension on String { String capitalize() { return "${this[0].toUpperCase()}${this.substring(1)}"; } }