// smart_home.dart import 'dart:io'; const double MIN_TEMP = 15.0; const double MAX_TEMP = 30.0; void main() { bool lightsOn = false; double thermostat = 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('\nEnter your choice: '); String? choice = stdin.readLineSync(); if (choice == null) continue; switch (choice.trim()) { case '1': lightsOn = !lightsOn; print('Lights are now ${lightsOn ? "ON" : "OFF"}.'); break; case '2': stdout.write('Set thermostat temperature (${MIN_TEMP.toStringAsFixed(0)}°C - ${MAX_TEMP.toStringAsFixed(0)}°C): '); String? tempStr = stdin.readLineSync(); double? t = _parseDoubleInRange(tempStr, MIN_TEMP, MAX_TEMP); if (t == null) { print('Invalid temperature. Must be between ${MIN_TEMP.toInt()} and ${MAX_TEMP.toInt()}.'); } else { thermostat = t; print('Thermostat set to ${thermostat.toStringAsFixed(1)}°C.'); _fizzBuzzTempMessage(thermostat); } break; case '3': securityArmed = !securityArmed; print('Security system is now ${securityArmed ? "ARMED" : "DISARMED"}.'); break; case '4': _printStatus(lightsOn, thermostat, securityArmed); break; case '5': print('\nExiting the system. Goodbye!'); return; default: print('Invalid choice. Please enter 1-5.'); } } } double? _parseDoubleInRange(String? s, double min, double max) { if (s == null) return null; double? val = double.tryParse(s.trim()); if (val == null) return null; if (val < min || val > max) return null; return val; } void _printStatus(bool lightsOn, double thermostat, bool securityArmed) { print('\nSystem Status:'); print('- Lights: ${lightsOn ? "ON" : "OFF"}'); String tempNote = _tempNote(thermostat); print('- Thermostat: ${thermostat.toStringAsFixed(1)}°C - $tempNote'); print('- Security System: ${securityArmed ? "ARMED" : "DISARMED"}'); } String _tempNote(double t) { bool multipleOf3 = (t % 3).abs() < 1e-9; bool multipleOf5 = (t % 5).abs() < 1e-9; if (multipleOf3 && multipleOf5) return 'Perfect Day'; if (multipleOf3) return 'Cool Day'; if (multipleOf5) return 'Warm Day'; return 'Normal'; } void _fizzBuzzTempMessage(double t) { String note = _tempNote(t); print('Note: $note'); }