import 'dart:io'; const int MIN_TEMP = 15; const int MAX_TEMP = 30; void main() { bool lightsOn = false; int thermostat = 20; bool securityArmed = false; print('Welcome to the Smart Home Automation CLI!'); while (true) { print('\nChoose an option:'); print('1. Toggle Lights (on/off)'); print('2. Set Thermostat (15 - 30 °C)'); print('3. Arm/Disarm Security System'); print('4. View System Status'); print('5. Exit'); stdout.write('Enter choice (1-5): '); String? choice = stdin.readLineSync(); if (choice == null) { print('Invalid input. Try again.'); continue; } if (choice == '1') { switch (lightsOn) { case true: lightsOn = false; print('Lights turned OFF.'); break; case false: lightsOn = true; print('Lights turned ON.'); break; } } else if (choice == '2') { while (true) { stdout.write( 'Enter thermostat temperature (integer °C between $MIN_TEMP and $MAX_TEMP): ', ); String? tempInput = stdin.readLineSync(); if (tempInput == null) { print('Invalid input. Try again.'); continue; } int? temp = int.tryParse(tempInput); if (temp == null) { print('Please enter an integer value.'); continue; } if (temp < MIN_TEMP || temp > MAX_TEMP) { print('Temperature must be between $MIN_TEMP and $MAX_TEMP.'); continue; } thermostat = temp; print('Thermostat set to ${thermostat}°C.'); break; } } else if (choice == '3') { switch (securityArmed) { case true: securityArmed = false; print('Security system DISARMED.'); break; case false: securityArmed = true; print('Security system ARMED.'); break; } } else if (choice == '4') { String lightsStatus = lightsOn ? 'ON' : 'OFF'; String securityStatus = securityArmed ? 'ARMED' : 'DISARMED'; String dayMsg = ''; bool by3 = (thermostat % 3 == 0); bool by5 = (thermostat % 5 == 0); if (by3 && by5) { dayMsg = 'Perfect Day'; } else if (by3) { dayMsg = 'Cool Day'; } else if (by5) { dayMsg = 'Warm Day'; } print('\n--- System Status ---'); print('Lights: $lightsStatus'); print( 'Thermostat: ${thermostat}°C ${dayMsg.isNotEmpty ? "- $dayMsg" : ""}', ); print('Security System: ${securityStatus.toUpperCase()}'); print('---------------------\n'); } else if (choice == '5') { print('Exiting Smart Home CLI. Goodbye!'); break; } else { print('Invalid choice. Please select 1-5.'); } } }