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'); stdout.write('Enter your choice: '); String? choiceInput = stdin.readLineSync(); if (choiceInput == null || choiceInput.trim().isEmpty) { print('Invalid input. Please try again.'); continue; } int? choice = int.tryParse(choiceInput.trim()); if (choice == null) { print('Please enter a valid number.'); continue; } if (choice == 5) { print('Exiting the system. Goodbye!'); break; } switch (choice) { case 1: lightsOn = !lightsOn; print('Lights are now ${lightsOn ? "ON" : "OFF"}.'); break; case 2: bool validTemp = false; while (!validTemp) { stdout.write('Set thermostat ($minTemp-$maxTemp): '); String? tempInput = stdin.readLineSync(); if (tempInput != null) { int? temp = int.tryParse(tempInput.trim()); if (temp != null && temp >= minTemp && temp <= maxTemp) { thermostat = temp; print('Thermostat set to $temp°C.'); validTemp = true; } else { print('Must be $minTemp-$maxTemp.'); } } } break; case 3: print('Security: ${securityArmed ? "ARMED" : "DISARMED"}'); stdout.write('${securityArmed ? "Disarm" : "Arm"}? (y/n): '); String? input = stdin.readLineSync(); if (input != null && input.trim().toLowerCase() == 'y') { securityArmed = !securityArmed; print('Security now ${securityArmed ? "ARMED" : "DISARMED"}.'); } break; case 4: String lightsStatus = lightsOn ? 'ON' : 'OFF'; String dayLabel = ''; if (thermostat % 3 == 0 && thermostat % 5 == 0) { dayLabel = 'Perfect Day'; } else if (thermostat % 3 == 0) { dayLabel = 'Cool Day'; } else if (thermostat % 5 == 0) { dayLabel = 'Warm Day'; } String thermostatLine = dayLabel.isEmpty ? '$thermostat°C' : '$thermostat°C - $dayLabel'; String securityStatus = securityArmed ? 'ARMED' : 'DISARMED'; print('\nSystem Status:'); print('- Lights: $lightsStatus'); print('- Thermostat: $thermostatLine'); print('- Security: $securityStatus'); break; default: print('Invalid choice.'); } } }