import 'dart:io'; // 7. Final/Const Variables: Use const for temperature constraints const int MIN_TEMP = 15; const int MAX_TEMP = 30; // 2. Device Status: Global variables for device states bool lightsOn = false; // default: off int thermostatTemp = 20; // default: 20°C String securityStatus = 'disarmed'; // default: disarmed // Function to read user input String? readInput() { stdout.write('Enter your choice: '); return stdin.readLineSync(); } // Function to read and validate temperature input int? readTemperature() { stdout.write('Set thermostat temperature ($MIN_TEMP°C - $MAX_TEMP°C): '); String? input = stdin.readLineSync(); try { int temp = int.parse(input!); // 8. Logical & Relational Operators: Validate input range if (temp >= MIN_TEMP && temp <= MAX_TEMP) { return temp; } else { print('Invalid temperature. Please choose a value between $MIN_TEMP°C and $MAX_TEMP°C.'); return null; } } catch (e) { print('Invalid input. Please enter a whole number for the temperature.'); return null; } } // Function to display the main menu void displayMenu() { 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'); } // Function to display the system status (including FizzBuzz-like logic) void viewStatus() { // 5. Implement a FizzBuzz-like exercise String tempMessage = ''; // Check for multiples of 3 if (thermostatTemp % 3 == 0) { tempMessage += 'Cool Day'; } // Check for multiples of 5 if (thermostatTemp % 5 == 0) { if (tempMessage == 'Cool Day') { tempMessage = 'Perfect Day'; // Multiple of both 3 and 5 } else { tempMessage += 'Warm Day'; } } // 6. String Interpolation and Operations: print('\nSystem Status:'); // Use string interpolation to show state print('Lights: ${lightsOn ? 'ON' : 'OFF'}'); print('Thermostat: $thermostatTemp°C ${tempMessage.trim()}'); // Use string operation (toUpperCase) print('Security System: ${securityStatus.toUpperCase()}'); } // 1. Main Method: Program entry point void main() { print('Welcome to the Smart Home Automation System CLI!'); // 3. User Interaction: Use a loop for continuous interaction while (true) { displayMenu(); String? choice = readInput(); // 5. Control Flow: Use if/else for main control if (choice == '5') { print('Exiting the system. Goodbye!'); break; } else if (choice == '4') { viewStatus(); } else { // 5. Control Flow: Use switch for device commands switch (choice) { case '1': // Toggle lights lightsOn = !lightsOn; print('Lights are now ${lightsOn ? 'ON' : 'OFF'}.'); break; case '2': // Set thermostat temperature int? newTemp = readTemperature(); if (newTemp != null) { thermostatTemp = newTemp; print('Thermostat set to $thermostatTemp°C.'); } break; case '3': // Arm/disarm security system if (securityStatus == 'disarmed') { securityStatus = 'armed'; print('Security system is now ARMED.'); } else { securityStatus = 'disarmed'; print('Security system is now DISARMED.'); } break; default: print('Invalid choice. Please select an option from 1 to 5.'); } } } }