import 'dart:io'; void main() { const int minTemp = 15; const int maxTemp = 30; 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.isEmpty) { print('No input detected. Try again.'); continue; } int? choice = int.tryParse(choiceInput); if (choice == null) { print('Invalid input. Enter a number between 1 and 5.'); continue; } switch (choice) { case 1: lightsOn = !lightsOn; print('Lights are now ${lightsOn ? "ON" : "OFF"}.'); break; case 2: while (true) { stdout.write('Set thermostat temperature ($minTemp°C – $maxTemp°C): '); String? tempInput = stdin.readLineSync(); int? temp = int.tryParse(tempInput ?? ''); if (temp != null && temp >= minTemp && temp <= maxTemp) { thermostat = temp; print('Thermostat set to $thermostat°C.'); break; } else { print('Invalid temperature. Enter a value between $minTemp and $maxTemp.'); } } break; case 3: securityArmed = !securityArmed; print('Security System is now ${securityArmed ? "ARMED" : "DISARMED"}.'); break; case 4: print('System Status:'); print('- Lights: ${lightsOn ? "ON" : "OFF"}'); String dayMessage = ''; if (thermostat % 3 == 0 && thermostat % 5 == 0) { dayMessage = ' – Perfect Day'; } else if (thermostat % 3 == 0) { dayMessage = ' – Cool Day'; } else if (thermostat % 5 == 0) { dayMessage = ' – Warm Day'; } print('- Thermostat: $thermostat°C$dayMessage'); print('- Security System: ${securityArmed ? "ARMED" : "DISARMED"}'); break; case 5: print('Exiting the system. Goodbye!'); return; default: print('Invalid choice. Enter a number between 1 and 5.'); } } }