// Smart Home Automation CLI (Dart) // Filename suggestion: AsmaKhaledAlamoudi_252001042_question1.txt import 'dart:io'; const int MIN_TEMP = 15; const int MAX_TEMP = 30; void main() { bool lightsOn = false; // default: lightsOff int thermostat = 20; // default: 20°C bool securityArmed = false; // default: disarmed print('Welcome to Smart Home CLI!'); while (true) { print('\nChoose an option:'); print('1. Control Lights'); print('2. Set Thermostat'); print('3. Control Security System'); print('4. View System Status'); print('5. Exit'); stdout.write('Enter choice (1-5): '); String? input = stdin.readLineSync(); if (input == null) continue; if (input == '5') { print('Exiting... Goodbye!'); break; } // Use if/else to handle top-level choices if (input == '1' || input == '2' || input == '3' || input == '4') { switch (input) { case '1': // Lights commands print('\nLights:'); print('a. Turn ON'); print('b. Turn OFF'); stdout.write('Choose (a/b): '); String? c = stdin.readLineSync(); if (c != null && c.toLowerCase() == 'a') { lightsOn = true; print('Lights turned ON.'); } else if (c != null && c.toLowerCase() == 'b') { lightsOn = false; print('Lights turned OFF.'); } else { print('Invalid lights command.'); } break; case '2': // Thermostat commands stdout.write('\nEnter desired temperature (${MIN_TEMP}-${MAX_TEMP} °C): '); String? tempStr = stdin.readLineSync(); if (tempStr == null) { print('No input.'); break; } int? temp = int.tryParse(tempStr); if (temp == null) { print('Please enter a valid integer temperature.'); break; } // Validate using logical & relational operators if (temp < MIN_TEMP || temp > MAX_TEMP) { print('Temperature must be between $MIN_TEMP and $MAX_TEMP.'); } else { thermostat = temp; print('Thermostat set to $thermostat°C.'); } break; case '3': // Security system print('\nSecurity System:'); print('a. Arm'); print('b. Disarm'); stdout.write('Choose (a/b): '); String? s = stdin.readLineSync(); if (s != null && s.toLowerCase() == 'a') { securityArmed = true; print('Security system ARMED.'); } else if (s != null && s.toLowerCase() == 'b') { securityArmed = false; print('Security system DISARMED.'); } else { print('Invalid security command.'); } break; case '4': // View system status with string interpolation and operations String lightsStatus = lightsOn ? 'ON' : 'OFF'; String securityStatus = securityArmed ? 'ARMED' : 'DISARMED'; // FizzBuzz-like exercise for thermostat String tempNote = ''; bool mult3 = (thermostat % 3 == 0); bool mult5 = (thermostat % 5 == 0); if (mult3 && mult5) { tempNote = ' - Perfect Day'; } else if (mult3) { tempNote = ' - Cool Day'; } else if (mult5) { tempNote = ' - Warm Day'; } print('\n--- System Status ---'); // Use string interpolation print('Lights: $lightsStatus'); print('Thermostat: ${thermostat}°C$tempNote'); // Show security status in uppercase (string operation) print('Security: ${securityStatus.toUpperCase()}'); print('---------------------'); break; } } else { print('Please enter a valid choice between 1 and 5.'); } } }