import 'dart:io'; // 7. Final/Const Variables: استخدام const للحد الأقصى والأدنى لدرجة الحرارة[cite: 39]. const int MIN_TEMP = 15; const int MAX_TEMP = 30; // 2. Device Status: تهيئة حالة الأجهزة الافتراضية[cite: 17]. bool lightsOn = false; // (off) int thermostatTemp = 20; // (20°C) String securityStatus = "disarmed"; // (disarmed) void main() { // 1. Main Method: يبدأ البرنامج ويعرض خيارات المستخدم[cite: 11]. print("========================================="); print("🏠 Welcome to the Smart Home System! 🏠"); print("========================================="); // 3. User Interaction & 5. Control Flow: استخدام حلقة للسماح بالتفاعل المستمر[cite: 19, 29]. bool running = true; while (running) { displayMenu(); String? choice = stdin.readLineSync(); // 5. Control Flow: استخدام if/else للتعامل مع خيارات القائمة[cite: 29]. if (choice == '1') { toggleLights(); // تشغيل/إيقاف الأضواء } else if (choice == '2') { setThermostatTemp(); // ضبط درجة الحرارة } else if (choice == '3') { armDisarmSecurity(); // تسليح/نزع تسليح نظام الأمان } else if (choice == '4') { viewSystemStatus(); // عرض حالة النظام } else if (choice == '5') { running = false; print("Exiting the system. Goodbye!"); // print("========================================="); } else { print("⚠️ Invalid choice. Please enter a number between 1 and 5."); } print("-----------------------------------------"); } } void displayMenu() { print("\nPlease choose an action:"); print("1. Toggle lights"); print("2. Set thermostat temperature"); print("3. Arm/disarm security system"); print("4. View system status"); print("5. Exit"); stdout.write("Enter your choice: "); } void toggleLights() { // 5. Control Flow: يمكن استخدام switch هنا أو if/else. lightsOn = !lightsOn; String status = lightsOn ? "ON" : "OFF"; print("Lights are now $status."); } void setThermostatTemp() { // 6. String Interpolation: استخدام استيفاء السلاسل لعرض النطاق[cite: 34]. stdout.write("Set thermostat temperature ($MIN_TEMP°C - $MAX_TEMP°C): "); String? input = stdin.readLineSync(); int? newTemp = int.tryParse(input ?? ""); // 4. Input Validation & 8. Logical & Relational Operators: التحقق من أن القيمة ضمن النطاق[cite: 27, 40]. if (newTemp != null && newTemp >= MIN_TEMP && newTemp <= MAX_TEMP) { thermostatTemp = newTemp; print("Thermostat set to ${thermostatTemp}°C."); } else { print("❌ Invalid temperature. Must be a number between $MIN_TEMP and $MAX_TEMP."); } } void armDisarmSecurity() { if (securityStatus == "disarmed") { securityStatus = "armed"; print("Security System is now ARMED."); } else { securityStatus = "disarmed"; print("Security System is now DISARMED."); } } void viewSystemStatus() { print("System Status:"); // 6. String Operations: تحويل حالة الجهاز إلى حروف كبيرة[cite: 35]. String securityDisplay = securityStatus.toUpperCase(); // 5. FizzBuzz-like exercise: تطبيق القاعدة على درجة الحرارة[cite: 31, 32]. String tempMessage = ""; if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) { tempMessage = "Perfect Day"; } else if (thermostatTemp % 3 == 0) { tempMessage = "Cool Day"; } else if (thermostatTemp % 5 == 0) { tempMessage = "Warm Day"; } // 6. String Interpolation: استخدام استيفاء السلاسل لعرض جميع القيم[cite: 34]. print("Lights: ${lightsOn ? 'ON' : 'OFF'}"); print("Thermostat: ${thermostatTemp}°C $tempMessage"); print("Security System: $securityDisplay"); } Bash dart smart_home_system.dart 2 30 4