import 'dart:io'; void main() { // Constants for temperature range const int minTemp = 15; const int maxTemp = 30; // Initialize device statuses String lightsStatus = 'off'; int thermostatTemp = 20; String securityStatus = 'disarmed'; bool running = true; while (running) { print('\nSmart Home Automation System'); 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'); stdout.write('Choose an option (1-5): '); String? input = stdin.readLineSync(); int? choice = int.tryParse(input ?? ''); if (choice == null || choice < 1 || choice > 5) { print('Invalid choice. Please enter a number between 1 and 5.'); continue; } // Use if/else for main user choices if (choice == 1) { // Toggle lights lightsStatus = (lightsStatus == 'off') ? 'on' : 'off'; print('Lights are now ${lightsStatus.toUpperCase()}.'); } else if (choice == 2) { // Set thermostat temperature stdout.write('Enter temperature (${minTemp}°C to ${maxTemp}°C): '); String? tempInput = stdin.readLineSync(); int? temp = int.tryParse(tempInput ?? ''); if (temp == null || temp < minTemp || temp > maxTemp) { print('Invalid temperature. Please enter a value between $minTemp and $maxTemp.'); } else { thermostatTemp = temp; print('Thermostat set to ${thermostatTemp}°C.'); } } else if (choice == 3) { // Toggle security system securityStatus = (securityStatus == 'disarmed') ? 'armed' : 'disarmed'; print('Security system is now ${securityStatus.toUpperCase()}.'); } else if (choice == 4) { // View system status with string interpolation and operations String lightsDisplay = lightsStatus.toUpperCase(); String securityDisplay = securityStatus.toUpperCase(); String tempMessage = '$thermostatTemp°C'; // FizzBuzz-like logic for temperature if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) { tempMessage += ' - Perfect Day'; } else if (thermostatTemp % 3 == 0) { tempMessage += ' - Cool Day'; } else if (thermostatTemp % 5 == 0) { tempMessage += ' - Warm Day'; } print('System Status:'); print('Lights: $lightsDisplay'); print('Thermostat: $tempMessage'); print('Security System: $securityDisplay'); } else if (choice == 5) { // Exit running = false; print('Exiting the Smart Home Automation System. Goodbye!'); } } }