/// /// class: Club.cs /// ///This file contains the Club class, which manages the collection of devices in the polo club. ///It provides methods to add, assign, return, and generate reports for devices, as well as retrieve all wearables. /// /// Name: Rens Pastoor /// Studentnumber: 555408 /// Date: 11 May 2025 /// ///Version: 1 /// using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Windows.Forms; namespace PoloClubApp { /// /// Represents a Polo Club that manages a collection of devices. /// class Club { private string name; private List devices; /// /// Initializes a new instance of the Club class. /// /// The name of the club. public Club(string name) { this.name = name; this.devices = new List(); } /// /// Gets the name of the club (read-only). /// public string Name => this.name; // ----- Graded Methods ----- /// /// Retrieves all wearable devices (implementing IWearable interface). /// /// List of wearable devices. public List GetAllWearables() { return devices.Where(d => d is IWearable).ToList(); } /// /// Assigns a device to a player. /// /// Device ID. /// Player's name. /// Thrown if device is not found. public void AssignDevice(int id, string playerName) { var device = GetDeviceById(id) ?? throw new Exception("Device not found"); var waterResistance = (device as IWearable)?.GetWaterResistanceMeters(); device.AssignDevice(playerName, waterResistance); } /// /// Returns a device from a player. /// /// Device ID. /// True if successful, false if device not found. public bool ReturnDevice(int id) { var device = GetDeviceById(id); return device?.ReturnDevice() ?? false; } /// /// Gets all devices assigned to a specific player. /// /// Player's name. /// List of assigned devices. public List GetAllAssignedDevicesByPlayer(string playerName) { return devices.Where(d => d.PlayerName == playerName).ToList(); } /// /// Generates a formatted device report for a player. /// /// Player's name. /// Formatted report lines. public List GenerateReportPerPlayer(string playerName) { var assignedDevices = GetAllAssignedDevicesByPlayer(playerName); var report = new List { $"List of devices assigned to {playerName}", "Phones", "-" }; report.AddRange(assignedDevices .OfType() .Select(d => d.GetDetails())); report.AddRange(new[] { "Wearables", "-" }); report.AddRange(assignedDevices .Where(d => d is IWearable) .Select(d => d.GetDetails())); report.Add($"Total: {assignedDevices.Count} devices, " + $"{assignedDevices.Count(d => d is SmartPhone)} phones and " + $"{assignedDevices.Count(d => d is IWearable)} wearables"); return report; } // -----The provided code below will not be graded, therefore should not be changed----- /// /// Provides all devices to the caller. /// /// List of devices public List GetAllDevices(){ return this.devices; } /// /// Adds a device to the list of devices if unique id is provided. /// /// device to be added public void AddDevice(Device device) { foreach (Device dev in this.devices){ if (dev.Id == device.Id){ return; } } devices.Add(device); } /// /// Provides a device by a given id. /// /// the unique identity number of the requested device. /// A device when found, otherwise null public Device GetDeviceById(int id){ foreach (Device dev in this.devices){ if (dev.Id == id){ return dev; } } return null; } } }