import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to the Budget Management Application!'); while (true) { print('\nPlease choose an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); String? input = stdin.readLineSync(); int? choice = int.tryParse(input ?? ''); switch (choice) { case 1: addEntry(incomeList, 'income'); break; case 2: addEntry(expenseList, 'expense'); break; case 3: viewSummary(incomeList, expenseList); break; case 4: print('Exiting the application. Goodbye!'); return; default: print('Invalid choice. Please try again.'); } } } void addEntry(List> list, String type) { print('Enter ${type} description:'); String? description = stdin.readLineSync(); print('Enter ${type} amount:'); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (description != null && description.isNotEmpty && amount != null && amount > 0) { list.add({'description': description, 'amount': amount}); print('${type.capitalize()} added!'); } else { print('Invalid input. Please enter a valid description and positive amount.'); } } void viewSummary(List> incomeList, List> expenseList) { double totalIncome = 0; double totalExpense = 0; for (var entry in incomeList) { totalIncome += entry['amount']; } for (var entry in expenseList) { totalExpense += entry['amount']; } double net = totalIncome - totalExpense; double tax = net > 0 ? net * 0.15 : 0; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpense.toStringAsFixed(2)}'); print('Net ${net >= 0 ? 'profit' : 'loss'}: \$${net.abs().toStringAsFixed(2)}'); if (net > 0) { print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } } extension StringExtension on String { String capitalize() { return "${this[0].toUpperCase()}${this.substring(1)}"; } }