import 'dart:io'; void main() { // 1. الثوابت (Constants) [cite: 38, 39] const double minTemp = 15.0; const double maxTemp = 30.0; // 2. تهيئة القيم الافتراضية (Initialization) [cite: 13, 17] bool isLightsOn = false; double temperature = 20.0; String securityStatus = "disarmed"; print("Welcome to the Smart Home System! [cite: 42]"); // 3. حلقة التكرار للتفاعل المستمر (Loop) [cite: 19] bool running = true; while (running) { print("\nPlease choose an action: [cite: 43]"); print("1. Toggle lights [cite: 44]"); print("2. Set thermostat temperature [cite: 45]"); print("3. Arm/disarm security system [cite: 46]"); print("4. View system status [cite: 47]"); print("5. Exit [cite: 48]"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); // 4. استخدام switch للتعامل مع أوامر الأجهزة [cite: 30] switch (choice) { case '1': isLightsOn = !isLightsOn; // تبديل الحالة [cite: 21] print("Lights are now ${isLightsOn ? 'ON' : 'OFF'}. [cite: 50]"); break; case '2': stdout.write("Set thermostat temperature ($minTemp°C - $maxTemp°C): "); double? inputTemp = double.tryParse(stdin.readLineSync() ?? ""); // التحقق من المدخلات باستخدام المعاملات المنطقية [cite: 27, 41] if (inputTemp != null && inputTemp >= minTemp && inputTemp <= maxTemp) { temperature = inputTemp; print("Thermostat set to $temperature°C. [cite: 53]"); } else { print("Invalid temperature! Please enter a value between $minTemp and $maxTemp. [cite: 27]"); } break; case '3': // تبديل حالة نظام الأمان [cite: 23, 41] if (securityStatus == "disarmed") { securityStatus = "armed"; } else { securityStatus = "disarmed"; } print("Security System is now ${securityStatus.toUpperCase()}. "); break; case '4': // 5. عرض حالة النظام مع تمارين إضافية (String Interpolation) [cite: 34] print("\n--- System Status --- [cite: 55]"); print("Lights: ${isLightsOn ? 'ON' : 'OFF'} [cite: 56]"); // تمرين FizzBuzz لدرجة الحرارة String tempMessage = ""; if (temperature % 3 == 0 && temperature % 5 == 0) { tempMessage = "Perfect Day"; } else if (temperature % 3 == 0) { tempMessage = "Cool Day"; } else if (temperature % 5 == 0) { tempMessage = "Warm Day"; } print("Thermostat: $temperature°C $tempMessage [cite: 57]"); // تحويل النص للأحرف الكبيرة (String Operation) print("Security System: ${securityStatus.toUpperCase()} [cite: 58]"); break; case '5': running = false; print("Exiting the system. Goodbye! [cite: 60]"); break; default: print("Invalid choice. Please try again."); } } }