import 'dart:io'; void main() { const int MIN_TEMP = 15; const int MAX_TEMP = 30; bool lightsOn = false; double thermostatTemp = 20.0; 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.isEmpty) { print('Invalid input. Please try again.'); continue; } int choice = int.tryParse(choiceInput) ?? 0; switch (choice) { case 1: lightsOn = !lightsOn; print('Lights are now ${lightsOn ? 'ON' : 'OFF'}.'); break; case 2: stdout.write('Set thermostat temperature (${MIN_TEMP}°C - ${MAX_TEMP}°C): '); String? tempInput = stdin.readLineSync(); double temp = double.tryParse(tempInput ?? '') ?? 0.0; if (temp >= MIN_TEMP && temp <= MAX_TEMP) { thermostatTemp = temp; print('Thermostat set to ${thermostatTemp}°C.'); } else { print('Invalid temperature. Please enter between ${MIN_TEMP}°C and ${MAX_TEMP}°C.'); } break; case 3: securityArmed = !securityArmed; print('Security system is now ${securityArmed ? 'ARMED' : 'DISARMED'}.'); break; case 4: print('\nSystem Status:'); print('- Lights: ${lightsOn ? 'ON' : 'OFF'}'); String tempMessage; if (thermostatTemp % 15 == 0) { tempMessage = 'Perfect Day'; } else if (thermostatTemp % 3 == 0) { tempMessage = 'Cool Day'; } else if (thermostatTemp % 5 == 0) { tempMessage = 'Warm Day'; } else { tempMessage = ''; } print('- Thermostat: ${thermostatTemp}°C ${tempMessage.isNotEmpty ? '- $tempMessage' : ''}'); print('- Security System: ${securityArmed ? 'ARMED' : 'DISARMED'}'); break; case 5: print('Exiting the system. Goodbye!'); exit(0); default: print('Invalid choice. Please try again.'); } } }