import 'dart:io'; void main() { // 7. استخدام الثوابت (const) للقيم الثابتة const int minTemp = 15; const int maxTemp = 30; // 2. تهيئة حالة الأجهزة بالقيم الافتراضية bool isLightOn = false; int temperature = 20; bool isSecurityArmed = false; print("--- مرحباً بك في نظام أتمتة المنزل الذكي ---"); // 3. حلقة تكرار للسماح للمستخدم بالتفاعل المستمر bool running = true; while (running) { print("\nالرجاء اختيار أمر:"); print("1. التحكم بالأضواء (تشغيل/إطفاء)"); print("2. ضبط درجة الحرارة"); print("3. التحكم بالنظام الأمني (تفعيل/تعطيل)"); print("4. عرض حالة النظام"); print("5. خروج"); stdout.write("خيارك: "); String? input = stdin.readLineSync(); // 5. استخدام if/else للتعامل مع خيارات القائمة الرئيسية if (input == '1') { // 5. استخدام switch للتعامل مع أوامر الأجهزة print("أدخل (on) لتشغيل الضوء أو (off) لإطفائه:"); String? lightChoice = stdin.readLineSync()?.toLowerCase(); switch (lightChoice) { case 'on': isLightOn = true; print("تم تشغيل الأضواء."); break; case 'off': isLightOn = false; print("تم إطفاء الأضواء."); break; default: print("خيار غير صحيح."); } } else if (input == '2') { print("أدخل درجة الحرارة المطلوبة ($minTemp - $maxTemp):"); String? tempInput = stdin.readLineSync(); int? newTemp = int.tryParse(tempInput ?? ""); // 4 & 8. التحقق من المدخلات باستخدام العمليات المنطقية وال관계ية if (newTemp != null && newTemp >= minTemp && newTemp <= maxTemp) { temperature = newTemp; print("تم ضبط الحرارة على $temperature°C."); } else { print("خطأ: يرجى إدخال درجة حرارة صحيحة بين $minTemp و $maxTemp."); } } else if (input == '3') { print("أدخل (arm) لتفعيل الأمن أو (disarm) لتعطيله:"); String? securityChoice = stdin.readLineSync()?.toLowerCase(); switch (securityChoice) { case 'arm': isSecurityArmed = true; print("تم تفعيل النظام الأمني."); break; case 'disarm': isSecurityArmed = false; print("تم تعطيل النظام الأمني."); break; default: print("خيار غير صحيح."); } } else if (input == '4') { // 5. تمرين FizzBuzz-like لدرجة الحرارة String tempFeedback = ""; if (temperature % 3 == 0 && temperature % 5 == 0) { tempFeedback = "Perfect Day"; } else if (temperature % 3 == 0) { tempFeedback = "Cool Day"; } else if (temperature % 5 == 0) { tempFeedback = "Warm Day"; } // 6. استخدام String Interpolation و تحويل النصوص (toUpperCase) String lightStatus = isLightOn ? "ON" : "OFF"; String securityStatus = isSecurityArmed ? "armed" : "disarmed"; print("\n========== حالة النظام =========="); print("الأضواء: $lightStatus"); print("الترموستات: $temperature°C ${tempFeedback.isNotEmpty ? '($tempFeedback)' : ''}"); print("النظام الأمني: ${securityStatus.toUpperCase()}"); // تحويل النص لحروف كبيرة print("================================"); } else if (input == '5') { print("إغلاق النظام... وداعاً!"); running = false; } else { print("خيار غير صالح، حاول مرة أخرى."); } } }