A repository of exercises to support the training.
Imagine you are tasked with managing a fleet of smart devices (lights, sensors, thermostats) for a smart home system. Your job is to organize and filter the data to make it easier for the system to decide which devices need attention.
Your smart home system has various devices, each with different statuses (e.g., "On", "Off", "Idle"). You need to filter out the devices that are currently "Off" to avoid unnecessary processing.
Instructions:
DeviceID
, DeviceType
, and Status
.// Sample Data Structure
public class SmartDevice {
public int DeviceID { get; set; }
public string DeviceType { get; set; }
public string Status { get; set; }
}
// Example device list initialization and LINQ filtering
List<SmartDevice> devices =
[
new SmartDevice { DeviceID = 1, DeviceType = "Smart Light", Status = "On" },
new SmartDevice { DeviceID = 2, DeviceType = "Smart Thermostat", Status = "Off" },
new SmartDevice { DeviceID = 3, DeviceType = "Smart Camera", Status = "On" },
new SmartDevice { DeviceID = 4, DeviceType = "Smart Door Lock", Status = "Off" },
new SmartDevice { DeviceID = 5, DeviceType = "Smart Thermostat", Status = "On" },
new SmartDevice { DeviceID = 6, DeviceType = "Smart Light", Status = "On" }
];
Next, you'll sort the filtered devices by their type (e.g., lights, thermostats) and by priority, which is determined by the device type (thermostats have higher priority than lights).
Instructions:
DeviceType
and then by DeviceID
.Example priority function:
// Method to define device type priority (thermostats have the highest priority)
public static int GetDevicePriority(string deviceType)
{
switch (deviceType)
{
case "Smart Thermostat":
return 2; // Highest priority
case "Smart Light":
return 1; // Lower priority
default:
return 0; // Default priority for other devices
}
}
Happy coding!