import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; bool running = true; print('Welcome to the Budget Management Application!'); while (running) { 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': // Handle Income stdout.write('Enter income description: '); String desc = stdin.readLineSync() ?? 'Untitled Income'; stdout.write('Enter income amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { incomeList.add({'description': desc, 'amount': amount}); print('Income added!'); } else { print('Invalid amount. Please enter a positive number.'); } break; case '2': // Handle Expenses stdout.write('Enter expense description: '); String desc = stdin.readLineSync() ?? 'Untitled Expense'; stdout.write('Enter expense amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { expenseList.add({'description': desc, 'amount': amount}); print('Expense added!'); } else { print('Invalid amount. Please enter a positive number.'); } break; case '3': // View Summary & Calculations double totalIncome = 0; double totalExpenses = 0; for (var item in incomeList) { totalIncome += item['amount']; } for (var item in expenseList) { totalExpenses += item['amount']; } double netResult = totalIncome - totalExpenses; // Tax Calculation using Ternary Operator // Tax is 15% of net profit, only if profit > 0 double tax = netResult > 0 ? netResult * 0.15 : 0.0; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(0)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(0)}'); if (netResult >= 0) { print('Net profit: \$${netResult.toStringAsFixed(0)}'); print('Tax to be paid: \$${tax.toStringAsFixed(0)}'); } else { print('Net loss: \$${netResult.abs().toStringAsFixed(0)}'); print('No tax to be paid on losses.'); } break; case '4': print('Exiting the application. Goodbye!'); running = false; break; default: print('Invalid choice, please try again.'); } } }