import 'dart:io'; void main() { // Initialize devices with default values bool lightsOn = false; int thermostatTemp = 20; bool securityArmed = false; // Constants const int minTemp = 15; const int maxTemp = 30; print('| Welcome to the Smart Home System! |'); // Main loop for user interaction while (true) { print('| Please 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('\nEnter your choice: '); String? choice = stdin.readLineSync(); // Handle user choice if (choice == '1') { // Toggle lights lightsOn = !lightsOn; print('Lights are now ${lightsOn ? 'ON' : 'OFF'}.'); } else if (choice == '2') { // Set thermostat temperature while (true) { stdout.write('Set thermostat temperature (${minTemp}°C – ${maxTemp}°C): '); String? tempInput = stdin.readLineSync(); try { int temp = int.parse(tempInput!); if (temp >= minTemp && temp <= maxTemp) { thermostatTemp = temp; print('Thermostat set to ${temp}°C.'); break; } else { print('Invalid temperature! Please enter a value between $minTemp and $maxTemp.'); } } catch (e) { print('Invalid input! Please enter a valid number.'); } } } else if (choice == '3') { // Arm/disarm security system securityArmed = !securityArmed; print('Security system is now ${securityArmed ? 'ARMED' : 'DISARMED'}.'); } else if (choice == '4') { // View system status print('System Status:'); // Lights status print('- Lights: ${lightsOn ? 'ON' : 'OFF'}'); // Thermostat status with FizzBuzz-like exercise String dayMessage = ''; if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) { dayMessage = ' - Perfect Day'; } else if (thermostatTemp % 3 == 0) { dayMessage = ' - Cool Day'; } else if (thermostatTemp % 5 == 0) { dayMessage = ' - Warm Day'; } print('- Thermostat: ${thermostatTemp}°C$dayMessage'); // Security system status (converted to uppercase) String securityStatus = securityArmed ? 'ARMED' : 'DISARMED'; print('- Security System: $securityStatus'); } else if (choice == '5') { // Exit program print('Exiting the system. Goodbye!'); break; } else { print('Invalid choice! Please enter a number between 1 and 5.'); } print(''); // Empty line for better readability } }