import 'dart:io'; void main() { // Smart Home Default Values bool lightsOn = false; // lightsOff by default int thermostat = 20; // default 20°C bool securityArmed = false; // disarmed by default const int minTemp = 15; const int maxTemp = 30; print("Welcome to the Smart Home System!"); while (true) { 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("\nEnter your choice: "); String? input = stdin.readLineSync(); int? choice = int.tryParse(input ?? ""); if (choice == null) { print("Invalid input. Please enter a number from 1 to 5."); continue; } // if/else to handle user choices (as required) if (choice == 1 || choice == 2 || choice == 3) { // switch to handle device commands (as required) switch (choice) { case 1: lightsOn = !lightsOn; print("Lights are now ${lightsOn ? "ON" : "OFF"}."); break; case 2: int? newTemp = _readTemperature(minTemp, maxTemp); if (newTemp != null) { thermostat = newTemp; print("Thermostat set to $thermostat°C."); } break; case 3: stdout.write("Type 1 to ARM or 0 to DISARM: "); String? secInput = stdin.readLineSync(); int? secChoice = int.tryParse(secInput ?? ""); // logical & relational operators if (secChoice == 1) { securityArmed = true; print("Security System is now ARMED."); } else if (secChoice == 0) { securityArmed = false; print("Security System is now DISARMED."); } else { print("Invalid choice. Please type 1 or 0."); } break; } } else if (choice == 4) { _showStatus(lightsOn, thermostat, securityArmed); } else if (choice == 5) { print("Exiting the system. Goodbye!"); break; } else { print("Invalid choice. Please enter a number from 1 to 5."); } } } int? _readTemperature(int minTemp, int maxTemp) { while (true) { stdout.write("Set thermostat temperature ($minTemp°C - $maxTemp°C): "); String? tempInput = stdin.readLineSync(); int? temp = int.tryParse(tempInput ?? ""); if (temp == null) { print("Invalid input. Please enter a valid number."); continue; } // input validation using logical & relational operators if (temp < minTemp || temp > maxTemp) { print("Temperature must be between $minTemp and $maxTemp. Try again."); continue; } return temp; } } void _showStatus(bool lightsOn, int thermostat, bool securityArmed) { // FizzBuzz-like temperature label String tempLabel = ""; if (thermostat % 3 == 0 && thermostat % 5 == 0) { tempLabel = "Perfect Day"; } else if (thermostat % 3 == 0) { tempLabel = "Cool Day"; } else if (thermostat % 5 == 0) { tempLabel = "Warm Day"; } // string operations: armed -> ARMED (uppercase) String securityText = (securityArmed ? "armed" : "disarmed").toUpperCase(); print("\nSystem Status:"); print("- Lights: ${lightsOn ? "ON" : "OFF"}"); print("- Thermostat: $thermostat°C${tempLabel.isNotEmpty ? " - $tempLabel" : ""}"); print("- Security System: $securityText"); }