import 'dart:io'; // Constants using final (since const can't be used with runtime values) const double MIN_TEMP = 15.0; const double MAX_TEMP = 30.0; void main() { // Initialize device status bool lightsOn = false; double thermostatTemp = 20.0; bool securityArmed = false; print("=" * 50); print("Welcome to the Smart Home System!"); print("=" * 50); bool running = true; while (running) { // Display menu 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? choice = stdin.readLineSync(); // Use if/else to handle main menu choices if (choice == '1') { // Toggle lights lightsOn = !lightsOn; print("Lights are now ${lightsOn ? 'ON' : 'OFF'}."); } else if (choice == '2') { // Set thermostat temperature stdout.write("Set thermostat temperature ($MIN_TEMP°C - $MAX_TEMP°C): "); String? tempInput = stdin.readLineSync(); if (tempInput != null) { double? temp = double.tryParse(tempInput); // Input validation using logical operators if (temp != null && temp >= MIN_TEMP && temp <= MAX_TEMP) { thermostatTemp = temp; print("Thermostat set to ${thermostatTemp}°C"); } else { print("Invalid temperature! Please enter a value between $MIN_TEMP°C and $MAX_TEMP°C."); } } } else if (choice == '3') { // Arm/disarm security system using switch print("\nSecurity System Options:"); print("1. Arm"); print("2. Disarm"); stdout.write("Enter your choice: "); String? secChoice = stdin.readLineSync(); // Switch statement for security commands switch (secChoice) { case '1': securityArmed = true; print("Security system ARMED."); break; case '2': securityArmed = false; print("Security system DISARMED."); break; default: print("Invalid choice!"); } } else if (choice == '4') { // View system status displaySystemStatus(lightsOn, thermostatTemp, securityArmed); } else if (choice == '5') { // Exit running = false; print("\nExiting the system. Goodbye!"); } else { print("Invalid choice! Please enter 1-5."); } } } void displaySystemStatus(bool lightsOn, double temp, bool securityArmed) { print("\n" + "=" * 30); print("System Status:"); print("- Lights: ${lightsOn ? 'ON' : 'OFF'}"); // String interpolation with FizzBuzz-like exercise String tempMessage = "$temp°C"; // Check for multiples bool multipleOf3 = temp % 3 == 0; bool multipleOf5 = temp % 5 == 0; if (multipleOf3 && multipleOf5) { tempMessage += " - Perfect Day!"; } else if (multipleOf3) { tempMessage += " - Cool Day"; } else if (multipleOf5) { tempMessage += " - Warm Day"; } print("- Thermostat: $tempMessage"); // String operations - converting to uppercase String securityStatus = securityArmed ? "armed" : "disarmed"; print("- Security System: ${securityStatus.toUpperCase()}"); print("=" * 30); }