import 'dart:io'; const int minTemp = 15; const int maxTemp = 30; void main() { bool lightsOn = false; int thermostat = 20; bool securityArmed = false; while (true) { stdout.writeln('\n=== Smart Home ==='); stdout.writeln('1) Toggle lights On/Off'); stdout.writeln('2) Set thermostat ($minTemp–$maxTemp °C)'); stdout.writeln('3) Security: arm/disarm'); stdout.writeln('4) Show status'); stdout.writeln('5) Exit'); stdout.write('Your choice: '); final input = stdin.readLineSync()?.trim() ?? ''; switch (input) { case '1': if (lightsOn) { lightsOn = false; stdout.writeln('Lights turned OFF.'); } else { lightsOn = true; stdout.writeln('Lights turned ON.'); } break; case '2': stdout.write('Enter a temperature between $minTemp and $maxTemp: '); final tStr = stdin.readLineSync()?.trim() ?? ''; final t = int.tryParse(tStr); if (t != null && t >= minTemp && t <= maxTemp) { thermostat = t; stdout.writeln('Thermostat set to $thermostat°C'); } else { stdout.writeln('Invalid value. Please enter a number between $minTemp and $maxTemp.'); } break; case '3': stdout.write('Type arm or disarm: '); final cmd = (stdin.readLineSync() ?? '').trim().toLowerCase(); if (cmd == 'arm') { if (!securityArmed) { securityArmed = true; stdout.writeln('System armed.'); } else { stdout.writeln('System already armed.'); } } else if (cmd == 'disarm') { if (securityArmed) { securityArmed = false; stdout.writeln('System disarmed.'); } else { stdout.writeln('System already disarmed.'); } } else { stdout.writeln('Unknown command.'); } break; case '4': final lightsStatus = lightsOn ? 'ON' : 'OFF'; final securityStatus = securityArmed ? 'ARMED' : 'DISARMED'; final tag = _tempTag(thermostat); stdout.writeln( 'Status: Lights=$lightsStatus | Temp=$thermostat°C${tag.isEmpty ? '' : ' [$tag]'} | Security=$securityStatus'); break; case '5': stdout.writeln('Exited.'); return; default: stdout.writeln('Invalid choice.'); } } } String _tempTag(int t) { final mult3 = t % 3 == 0; final mult5 = t % 5 == 0; if (mult3 && mult5) return 'Perfect Day'; if (mult3) return 'Cool Day'; if (mult5) return 'Warm Day'; return ''; }