[18/09/47 05:51 ص] .: import 'dart:io'; void main() { // قوائم لتخزين بيانات الدخل والمصروفات List> incomeList = []; List> expenseList = []; bool isRunning = true; // رسالة ترحيب print('==================================='); print(' مرحباً بك في تطبيق إدارة الميزانية'); print('==================================='); // الحلقة الرئيسية للبرنامج while (isRunning) { // عرض القائمة print('\nالرجاء اختيار إحدى العمليات التالية:'); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص المالي'); print('4. خروج'); stdout.write('اختيارك: '); String? choice = stdin.readLineSync(); // التعامل مع اختيار المستخدم باستخدام if/else if (choice == '1') { addEntry(incomeList, 'دخل'); } else if (choice == '2') { addEntry(expenseList, 'مصروف'); } else if (choice == '3') { showSummary(incomeList, expenseList); } else if (choice == '4') { print('شكراً لاستخدام التطبيق. إلى اللقاء!'); isRunning = false; } else { print('اختيار غير صالح. الرجاء المحاولة مرة أخرى.'); } } } // دالة لإضافة دخل أو مصروف جديد void addEntry(List> list, String entryType) { print('\n--- إضافة $entryType جديد ---'); // إدخال الوصف stdout.write('أدخل الوصف: '); String? description = stdin.readLineSync(); if (description == null || description.trim().isEmpty) { print('الوصف لا يمكن أن يكون فارغاً.'); return; } // إدخال المبلغ مع التحقق من الصحة double? amount; while (amount == null) { stdout.write('أدخل المبلغ (يجب أن يكون رقماً موجباً): '); String? amountInput = stdin.readLineSync(); if (amountInput != null) { try { amount = double.parse(amountInput); // التحقق من أن المبلغ ليس سالباً أو صفراً باستخدام if/else if (amount <= 0) { print('خطأ: المبلغ يجب أن يكون أكبر من صفر.'); amount = null; // إعادة تعيين القيمة لتكرار الطلب } } catch (e) { print('خطأ: الرجاء إدخال رقم صحيح.'); } } } // إضافة البيانات إلى القائمة list.add({description! : amount}); print('تم إضافة $entryType بقيمة $amount بنجاح.'); } // دالة عرض الملخص المالي void showSummary(List> incomeList, List> expenseList) { print('\n========== الملخص المالي =========='); // حساب إجمالي الدخل double totalIncome = 0.0; print('\n-- الدخل --'); if (incomeList.isEmpty) { print('لا يوجد دخل مسجل.'); } else { for (var entry in incomeList) { entry.forEach((description, amount) { print('$description: $amount'); totalIncome += amount; }); } } // حساب إجمالي المصروفات double totalExpenses = 0.0; print('\n-- المصروفات --'); if (expenseList.isEmpty) { print('لا يوجد مصروفات مسجلة.'); } else { for (var entry in expenseList) { entry.forEach((description, amount) { print('$description: $amount'); totalExpenses += amount; }); } } // عرض الإجماليات باستخدام string interpolation print('\n------------------------'); print('إجمالي الدخل: $totalIncome'); print('إجمالي المصروفات: $totalExpenses'); // حساب صافي الربح أو الخسارة double netBalance = totalIncome - totalExpenses; // استخدام if/else لعرض النتيجة المناسبة if (netBalance > 0) { print('------------------------'); print('صافي الربح: $netBalance'); // ===== تمرين الضريبة الاختياري ===== // استخدام ternary operator للتأكد من أن الضريبة تُحتسب فقط في حالة الربح double tax = netBalance > 0 ? netBalance * 0.15 : 0.0; print('الضريبة المستحقة (15%): $tax'); print('صافي الربح بعد الضريبة: ${netBalance - tax}'); // ==================================== } else if (netBalance < 0) { print('------------------------'); // تحويل الخسارة إلى رقم موجب للعرض print('صافي الخسارة: ${netBalance.abs()}'); } else { print('------------------------'); print('لا يوجد ربح أو خسارة (نقطة تعادل).'); } print('===================================\n'); }