import 'dart:io'; // Constant temperature limits const int minTemperature = 15; const int maxTemperature = 30; void main() { // Initial device states bool lightState = false; int currentTemp = 20; bool securityState = false; print("=== SMART HOME SYSTEM ==="); bool menuActive = true; while (menuActive) { print("\nSelect an option:"); print("1) Lights Control"); print("2) Thermostat Control"); print("3) Security System Control"); print("4) Show System Status"); print("5) Exit"); stdout.write("Enter choice: "); String? option = stdin.readLineSync(); if (option == null) continue; // Main control flow if (option == "1") { _handleDevice("lights", () { lightState = !lightState; print("Lights are now ${lightState ? "ON" : "OFF"}."); }); } else if (option == "2") { _handleDevice("thermostat", () { stdout.write("Set temperature ($minTemperature-$maxTemperature): "); String? input = stdin.readLineSync(); int? temp = int.tryParse(input ?? ""); if (temp == null || temp < minTemperature || temp > maxTemperature) { print("Invalid temperature. Try again."); } else { currentTemp = temp; print("Thermostat set to $currentTemp°C."); } }); } else if (option == "3") { _handleDevice("security", () { securityState = !securityState; print("Security system is now ${securityState ? "ARMED" : "DISARMED"}."); }); } else if (option == "4") { _showStatus(lightState, currentTemp, securityState); } else if (option == "5") { print("Shutting down system..."); menuActive = false; } else { print("Invalid option. Please try again."); } } } // Generic switch handler for devices void _handleDevice(String device, Function action) { switch (device) { case "lights": case "thermostat": case "security": action(); break; default: print("Unknown device."); } } // Display system status + FizzBuzz-like logic void _showStatus(bool lights, int temp, bool security) { String mood = ""; bool divisibleBy3 = temp % 3 == 0; bool divisibleBy5 = temp % 5 == 0; if (divisibleBy3 && divisibleBy5) { mood = "Perfect Day"; } else if (divisibleBy3) { mood = "Cool Day"; } else if (divisibleBy5) { mood = "Warm Day"; } print("\n=== SYSTEM STATUS ==="); print("Lights: ${lights ? "ON" : "OFF"}"); print("Thermostat: $temp°C ${mood.isNotEmpty ? "($mood)" : ""}"); print("Security: ${security ? "ARMED" : "DISARMED"}".toUpperCase()); }