// budget_app.dart import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; bool running = true; while (running) { print('\nWelcome to the Budget Management Application!'); print('Please 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(); if (choice == null) continue; if (choice == '1') { stdout.write('Enter income description: '); String? desc = stdin.readLineSync() ?? 'Income'; stdout.write('Enter income amount: '); String? amtStr = stdin.readLineSync(); double? amt = double.tryParse(amtStr ?? ''); if (amt == null || amt < 0) { print('Invalid amount. Must be a non-negative number.'); } else { incomeList.add({'description': desc, 'amount': amt}); print('Income added!'); } } else if (choice == '2') { stdout.write('Enter expense description: '); String? desc = stdin.readLineSync() ?? 'Expense'; stdout.write('Enter expense amount: '); String? amtStr = stdin.readLineSync(); double? amt = double.tryParse(amtStr ?? ''); if (amt == null || amt < 0) { print('Invalid amount. Must be a non-negative number.'); } else { expenseList.add({'description': desc, 'amount': amt}); print('Expense added!'); } } else if (choice == '3') { double totalIncome = incomeList.fold(0.0, (p, e) => p + (e['amount'] as double)); double totalExpenses = expenseList.fold(0.0, (p, e) => p + (e['amount'] as double)); double net = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net >= 0) { print('Net profit: \$${net.toStringAsFixed(2)}'); } else { print('Net loss: \$${(-net).toStringAsFixed(2)}'); } // Optional tax: 15% if profit (ternary) double tax = net > 0 ? net * 0.15 : 0.0; print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (choice == '4') { print('Exiting the application. Goodbye!'); running = false; } else { print('Invalid choice. Please choose 1-4.'); } } }