// Import dart:io to allow console input and output import 'dart:io'; void main() { // Define constant values for the minimum and maximum thermostat temperature const int minTemp = 15; const int maxTemp = 30; // Initialize device statuses bool lightsOn = false; // Lights are initially OFF int thermostat = 20; // Thermostat default temperature is 20°C bool securityArmed = false; // Security system is initially DISARMED // Display a welcome message print("Welcome to Smart Home Automation System!"); // Start an infinite loop to continuously show the menu until the user exits while (true) { // Display the menu options print("\n========= MENU ========="); 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"); // Prompt user to enter their choice stdout.write("Enter your choice (1-5): "); String? choice = stdin.readLineSync(); // Read user input from console // If input is null, skip this iteration and ask again if (choice == null) continue; // Handle the user's choice using a switch statement switch (choice) { // Option 1: Toggle lights on/off case '1': lightsOn = !lightsOn; // Change lights state print(lightsOn ? "Lights turned ON." : "Lights turned OFF."); break; // Option 2: Set thermostat temperature case '2': stdout.write("Enter temperature ($minTemp-$maxTemp): "); String? tempInput = stdin.readLineSync(); // Read temperature input if (tempInput != null) { int? temp = int.tryParse(tempInput); // Convert input to integer // Validate temperature range if (temp != null && temp >= minTemp && temp <= maxTemp) { thermostat = temp; print("Thermostat set to $thermostat°C"); } else { print("Invalid temperature! Must be between $minTemp and $maxTemp."); } } break; // Option 3: Toggle security system armed/disarmed case '3': securityArmed = !securityArmed; // Change security system state print(securityArmed ? "Security System ARMED." : "Security System DISARMED."); break; // Option 4: View the current system status case '4': // Convert boolean states to readable text String lightsStatus = lightsOn ? "ON" : "OFF"; String securityStatus = securityArmed ? "ARMED" : "DISARMED"; // FizzBuzz-like logic based on thermostat temperature if (thermostat % 3 == 0 && thermostat % 5 == 0) { print("Perfect Day - Temperature: $thermostat°C"); } else if (thermostat % 3 == 0) { print("Cool Day - Temperature: $thermostat°C"); } else if (thermostat % 5 == 0) { print("Warm Day - Temperature: $thermostat°C"); } else { print("Temperature: $thermostat°C"); } // Display lights and security system statuses print("Lights: $lightsStatus"); print("Security System: $securityStatus"); break; // Option 5: Exit the program case '5': print("Exiting Smart Home System. Goodbye!"); return; // Stop program execution // Handle invalid menu options default: print("Invalid choice! Please select between 1 and 5."); } } }