import 'dart:io'; const int minTemp = 15; const int maxTemp = 30; void main() { bool lightsOn = false; int thermostat = 20; bool securityArmed = false; bool running = true; print('Welcome to the Smart Home System!'); while (running) { 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 choice = stdin.readLineSync()?.trim() ?? ''; if (choice == '1') { print('\nLights control:'); print('1. Turn ON'); print('2. Turn OFF'); stdout.write('Choose (1/2): '); String lightChoice = stdin.readLineSync()?.trim() ?? ''; switch (lightChoice) { case '1': lightsOn = true; print('Lights are now ON.'); break; case '2': lightsOn = false; print('Lights are now OFF.'); break; default: print('Invalid option. Lights unchanged.'); } } else if (choice == '2') { print('\nThermostat control:'); print('1. Set temperature'); stdout.write('Choose: '); String tChoice = stdin.readLineSync()?.trim() ?? ''; switch (tChoice) { case '1': int newTemp = _readTempInRange(); thermostat = newTemp; print('Thermostat set to ${thermostat}°C.'); break; default: print('Invalid option. Thermostat unchanged.'); } } else if (choice == '3') { print('\nSecurity System:'); print('1. Arm'); print('2. Disarm'); stdout.write('Choose (1/2): '); String secChoice = stdin.readLineSync()?.trim() ?? ''; switch (secChoice) { case '1': securityArmed = true; print('Security system is now ARMED.'); break; case '2': securityArmed = false; print('Security system is now DISARMED.'); break; default: print('Invalid option. Security unchanged.'); } } else if (choice == '4') { String lightsStr = lightsOn ? 'ON' : 'OFF'; String secStr = (securityArmed ? 'armed' : 'disarmed').toUpperCase(); String label = _tempLabel(thermostat); print('\nSystem Status:'); print('- Lights: $lightsStr'); print('- Thermostat: ${thermostat}°C${label.isEmpty ? '' : ' – $label'}'); print('- Security System: $secStr'); } else if (choice == '5') { running = false; print('Exiting the system. Goodbye!'); } else { print('Invalid choice. Please try again.'); } } } int _readTempInRange() { while (true) { stdout.write('Enter temperature ($minTemp°C – $maxTemp°C): '); String input = stdin.readLineSync()?.trim() ?? ''; int? value = int.tryParse(input); if (value != null && value >= minTemp && value <= maxTemp) { return value; } print('Invalid temperature! Please enter a value between $minTemp and $maxTemp.'); } } String _tempLabel(int t) { bool mult3 = t % 3 == 0; bool mult5 = t % 5 == 0; if (mult3 && mult5) return 'Perfect Day'; if (mult3) return 'Cool Day'; if (mult5) return 'Warm Day'; return ''; }