import 'dart:io'; // Constant temperature limits const int minTemp = 15; const int maxTemp = 30; void main() { // Initial device states bool lightsOn = false; int thermostat = 20; bool securityArmed = false; print("=== SMART HOME CONTROL SYSTEM ==="); bool active = true; while (active) { print("\nChoose an option:"); print("1) Toggle Lights"); print("2) Set Thermostat"); print("3) Arm/Disarm Security System"); print("4) View System Status"); print("5) Exit"); stdout.write("Your choice: "); final choice = stdin.readLineSync(); if (choice == null) { print("Invalid input."); continue; } // if/else for main control flow if (choice == "1") { switch ("lights") { case "lights": lightsOn = !lightsOn; print("Lights are now ${lightsOn ? "ON" : "OFF"}."); break; } } else if (choice == "2") { switch ("thermostat") { case "thermostat": _setTemperature((value) => thermostat = value); break; } } else if (choice == "3") { switch ("security") { case "security": securityArmed = !securityArmed; print("Security system is now ${securityArmed ? "ARMED" : "DISARMED"}."); break; } } else if (choice == "4") { _displayStatus( lightsOn: lightsOn, thermostat: thermostat, securityArmed: securityArmed, ); } else if (choice == "5") { print("Exiting system... Goodbye."); active = false; } else { print("Invalid option. Try again."); } } } // Handles thermostat input and validation void _setTemperature(void Function(int) updateTemp) { stdout.write("Enter temperature ($minTemp–$maxTemp): "); final input = stdin.readLineSync(); if (input == null) { print("Invalid input."); return; } final temp = int.tryParse(input); if (temp == null) { print("Please enter a valid number."); return; } if (temp < minTemp || temp > maxTemp) { print("Temperature out of range."); return; } updateTemp(temp); print("Thermostat set to $temp°C."); } // Displays system status + FizzBuzz-like temperature logic void _displayStatus({ required bool lightsOn, required int thermostat, required bool securityArmed, }) { String mood = ""; bool mult3 = thermostat % 3 == 0; bool mult5 = thermostat % 5 == 0; if (mult3 && mult5) { mood = "Perfect Day"; } else if (mult3) { mood = "Cool Day"; } else if (mult5) { mood = "Warm Day"; } final lightsStatus = (lightsOn ? "ON" : "OFF").toUpperCase(); final securityStatus = (securityArmed ? "ARMED" : "DISARMED").toUpperCase(); print("\n=== SYSTEM STATUS ==="); print("Lights: $lightsStatus"); print("Thermostat: $thermostat°C ${mood.isNotEmpty ? "($mood)" : ""}"); print("Security System: $securityStatus"); }