import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print('\n=== تطبيق إدارة الميزانية ==='); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص'); print('4. الخروج'); stdout.write('اختر خيارك: '); String? choice = stdin.readLineSync(); if (choice == '1') { stdout.write('أدخل وصف الدخل: '); String? desc = stdin.readLineSync(); stdout.write('أدخل مبلغ الدخل: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount >= 0) { incomeList.add({desc ?? 'دخل غير محدد': amount}); print('تمت إضافة الدخل بنجاح.'); } else { print('مبلغ غير صالح.'); } } else if (choice == '2') { stdout.write('أدخل وصف المصروف: '); String? desc = stdin.readLineSync(); stdout.write('أدخل مبلغ المصروف: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount >= 0) { expenseList.add({desc ?? 'مصروف غير محدد': amount}); print('تمت إضافة المصروف بنجاح.'); } else { print('مبلغ غير صالح.'); } } else if (choice == '3') { double totalIncome = 0; double totalExpenses = 0; for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpenses += item.values.first; } double net = totalIncome - totalExpenses; if (net >= 0) { print('إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}'); print('إجمالي المصروفات: \$${totalExpenses.toStringAsFixed(2)}'); print('صافي الربح: \$${net.toStringAsFixed(2)}'); double tax = net * 0.15; print('الضريبة المستحقة (15% من الربح): \$${tax.toStringAsFixed(2)}'); } else { print('إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}'); print('إجمالي المصروفات: \$${totalExpenses.toStringAsFixed(2)}'); print('صافي الخسارة: \$${net.abs().toStringAsFixed(2)}'); } } else if (choice == '4') { print('تم الخروج من التطبيق.'); return; } else { print('خيار غير صالح. حاول مرة أخرى.'); } } }