// Author: Albatool // University ID: 251002039 // Question 2 - Budget Management Application import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print('\n=== Budget Management Application ==='); print('1. Add Income'); print('2. Add Expense'); print('3. Show Summary'); print('4. Exit'); stdout.write('Choose an option: '); String? choice = stdin.readLineSync(); switch (choice) { case '1': stdout.write('Enter income description: '); String? desc = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount > 0) { incomeList.add({desc ?? 'Income': amount}); print('Income added successfully.'); } else { print('Invalid amount.'); } break; case '2': stdout.write('Enter expense description: '); String? desc = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount > 0) { expenseList.add({desc ?? 'Expense': amount}); print('Expense added successfully.'); } else { print('Invalid amount.'); } break; case '3': double totalIncome = 0; double totalExpense = 0; for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpense += item.values.first; } double netProfit = totalIncome - totalExpense; double tax = netProfit > 0 ? netProfit * 0.15 : 0; print('\n--- Summary ---'); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpense.toStringAsFixed(2)}'); if (netProfit >= 0) { print('Net Profit: \$${netProfit.toStringAsFixed(2)}'); print('Tax (15%): \$${tax.toStringAsFixed(2)}'); } else { print('Net Loss: \$${netProfit.abs().toStringAsFixed(2)}'); } break; case '4': print('Goodbye 👋'); return; default: print('Invalid choice ❌'); } } }