Smart home import 'dart:io'; const int minTemp = 15; const int maxTemp = 30; void main() { bool lightsOn = false; int thermostat = 20; bool securityArmed = false; print('Welcome to the Smart Home System!'); while (true) { 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'); final choice = _readInt('Enter your choice: '); // if/else for menu choices (as required) if (choice == 1) { lightsOn = !lightsOn; print('Lights are now ${lightsOn ? "ON" : "OFF"}.'); } else if (choice == 2) { final temp = _readInt('Set thermostat temperature ($minTemp°C - $maxTemp°C): '); if (temp < minTemp || temp > maxTemp) { print('Invalid temperature. Please enter a value between $minTemp and $maxTemp.'); continue; // prompt again } thermostat = temp; print('Thermostat set to ${thermostat}°C.'); } else if (choice == 3) { // switch for device command (security actions) print('\nSecurity command:'); print('1. Arm'); print('2. Disarm'); final cmd = _readInt('Enter command: '); switch (cmd) { case 1: if (!securityArmed) { securityArmed = true; print('Security system is now ARMED.'); } else { print('Security system is already ARMED.'); } break; case 2: if (securityArmed) { securityArmed = false; print('Security system is now DISARMED.'); } else { print('Security system is already DISARMED.'); } break; default: print('Invalid command.'); } } else if (choice == 4) { final lightsText = lightsOn ? 'ON' : 'OFF'; final securityText = (securityArmed ? 'armed' : 'disarmed').toUpperCase(); final tempLabel = _tempFizzBuzzLabel(thermostat); print('\nSystem Status:'); print('- Lights: $lightsText'); print('- Thermostat: ${thermostat}°C${tempLabel.isEmpty ? "" : " - $tempLabel"}'); print('- Security System: $securityText'); } else if (choice == 5) { print('Exiting the system. Goodbye!'); break; } else { print('Invalid choice. Please try again.'); } } } String _tempFizzBuzzLabel(int t) { final is3 = (t % 3 == 0); final is5 = (t % 5 == 0); if (is3 && is5) return 'Perfect Day'; if (is3) return 'Cool Day'; if (is5) return 'Warm Day'; return ''; } int _readInt(String prompt) { while (true) { stdout.write(prompt); final input = stdin.readLineSync(); final value = int.tryParse(input ?? ''); if (value != null) return value; print('Please enter a valid number.'); } }