/* __scenario(1)__ 1-Light: Can be on or off 2-Thermostat: Adjustable between 15°C and 30°C 3-Security System: Can be armed or disarmed */ import 'dart:io'; // Define constants for temperature range const int minTemp = 15; const int maxTemp = 30; // Light class class Light { bool isOn = false; void toggle() { isOn = !isOn; print(isOn ? "Lights are ON." : "Lights are OFF."); } } // Thermostat class class Thermostat { double temperature = 20.0; void setTemperature(double temp) { if (temp < minTemp || temp > maxTemp) { print("Invalid temperature. Please enter a value between $minTemp and $maxTemp."); } else { temperature = temp; print("Thermostat set to $temperature°C."); } } } // Security System class class SecuritySystem { bool isArmed = false; void toggleSecurity() { isArmed = !isArmed; print(isArmed ? "Security System is ARMED." : "Security System is DISARMED."); } } // Main function with a command-line interface (CLI) void main() { // Initialize the devices Light light = Light(); Thermostat thermostat = Thermostat(); SecuritySystem securitySystem = SecuritySystem(); // User interactaion while (true) { print("\nSmart Home System:"); print("1. Turn Lights ON/OFF"); print("2. Set Thermostat Temperature"); print("3. Arm/Disarm Security System"); print("4. View System Status"); print("5. Exit"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); if (choice == '1') { light.toggle(); } else if (choice == '2') { stdout.write("Enter temperature between $minTemp°C and $maxTemp°C: "); String? tempInput = stdin.readLineSync(); if (tempInput != null && double.tryParse(tempInput) != null) { double temp = double.parse(tempInput); thermostat.setTemperature(temp); } else { print("Invalid input. Please enter a valid number."); } } else if (choice == '3') { securitySystem.toggleSecurity(); } else if (choice == '4') { displayStatus(light, thermostat, securitySystem); } else if (choice == '5') { print("Exiting Smart Home System"); break; } else { print("Invalid choice, please try again."); } } } // Display system status with additional logic for temperature void displayStatus(Light light, Thermostat thermostat, SecuritySystem securitySystem) { String lightStatus = light.isOn ? "ON" : "OFF"; String securityStatus = securitySystem.isArmed ? "ARMED" : "DISARMED"; String tempMessage = "Temperature: ${thermostat.temperature}°C"; // setting temperature comments based on degree if (thermostat.temperature % 3 == 0 && thermostat.temperature % 5 == 0) { tempMessage += " - Perfect Day:)"; } else if (thermostat.temperature % 3 == 0) { tempMessage += " - Cool Day:)"; } else if (thermostat.temperature % 5 == 0) { tempMessage += " - Warm Day:)"; } print("\nSystem Status:"); print("Lights: $lightStatus"); print(tempMessage); print("Security: $securityStatus"); }