import 'dart:io'; const int minTemperature = 15; const int maxTemperature = 30; void main() { bool lightsOn = false; int temperature = 20; bool securityArmed = false; bool running = true; print("=== Smart Home Automation System ==="); while (running) { print(""); print("Please choose an option:"); print("1. Control lights"); print("2. Set thermostat temperature"); print("3. Control security system"); print("4. View system status"); print("5. Exit"); stdout.write("Your choice: "); String? choice = stdin.readLineSync(); if (choice == '1') { lightsOn = controlLights(lightsOn); } else if (choice == '2') { temperature = setThermostat(temperature); } else if (choice == '3') { securityArmed = controlSecurity(securityArmed); } else if (choice == '4') { displayStatus(lightsOn, temperature, securityArmed); } else if (choice == '5') { print("Exiting the system. Goodbye!"); running = false; } else { print("Invalid choice. Please try again."); } } } bool controlLights(bool currentStatus) { print(""); print("=== Lights Control ==="); print("1. Turn lights ON"); print("2. Turn lights OFF"); stdout.write("Your choice: "); String? input = stdin.readLineSync(); switch (input) { case '1': print("Lights are now ON."); return true; case '2': print("Lights are now OFF."); return false; default: print("Invalid choice for lights. Status unchanged."); return currentStatus; } } int setThermostat(int currentTemperature) { print(""); print("=== Thermostat Control ==="); print("Current temperature: $currentTemperature°C"); stdout.write( "Enter new temperature ($minTemperature - $maxTemperature °C): "); String? input = stdin.readLineSync(); int? newTemp = int.tryParse(input ?? ""); if (newTemp != null && newTemp >= minTemperature && newTemp <= maxTemperature) { print("Temperature set to $newTemp°C."); return newTemp; } else { print( "Invalid temperature. Please enter a value between $minTemperature and $maxTemperature."); print("Temperature remains at $currentTemperature°C."); return currentTemperature; } } bool controlSecurity(bool currentStatus) { print(""); print("=== Security System Control ==="); print("1. Arm system"); print("2. Disarm system"); stdout.write("Your choice: "); String? input = stdin.readLineSync(); switch (input) { case '1': if (!currentStatus) { print("Security system is now ARMED."); return true; } else { print("Security system is already ARMED."); return currentStatus; } case '2': if (currentStatus) { print("Security system is now DISARMED."); return false; } else { print("Security system is already DISARMED."); return currentStatus; } default: print("Invalid choice for security system. Status unchanged."); return currentStatus; } } void displayStatus(bool lightsOn, int temperature, bool securityArmed) { print(""); print("=== System Status ==="); String lightsStatus = lightsOn ? "ON" : "OFF"; String securityStatus = securityArmed ? "armed" : "disarmed"; String securityStatusUpper = securityStatus.toUpperCase(); String dayMessage = ""; if (temperature % 3 == 0 && temperature % 5 == 0) { dayMessage = "Perfect Day"; } else if (temperature % 3 == 0) { dayMessage = "Cool Day"; } else if (temperature % 5 == 0) { dayMessage = "Warm Day"; } print("Lights: $lightsStatus"); print("Thermostat: $temperature°C"); print("Security System: $securityStatusUpper"); if (dayMessage.isNotEmpty) { print("$dayMessage at $temperature°C"); } }