/// /// 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 { class Club { private string name; // the name of the club private List devices; // a list of devices public Club(string name){ this.name = name; this.devices = new List(); } public string Name { get { return this.name; } } // read only property for Name //-----Provide your answers here----- public List GetAllWearables(){ List wearables = new List(); foreach (Device dev in this.devices){ if (dev is SmartWatch || dev is FitTracker){ wearables.Add(dev); } } return wearables; } public void AssignDevice(int id, string playerName){ Device device = GetDeviceById(id); if(device == null){ throw new Exception("Device not found"); } if (!(device is IWearable)){ device.AssignDevice(playerName, null); } else { IWearable wearable = (IWearable)device; device.AssignDevice(playerName, wearable.GetWaterResistanceMeters()); } } public bool ReturnDevice(int id){ Device device = GetDeviceById(id); return device.ReturnDevice(); } public List GetAllAssignedDevicesByPlayer(string playerName){ List assignedDevices = new List(); foreach (Device dev in this.devices){ if (dev.PlayerName == playerName){ assignedDevices.Add(dev); } } return assignedDevices; } public List GenerateReportPerPlayer(string playerName){ string returnString = "List of devices assigned to " + playerName; List lines = new List(); List assignedDevices = GetAllAssignedDevicesByPlayer(playerName); lines.Add(returnString); string currentDeviceType = "SmartPhone"; lines.Add("Phones"); lines.Add("-"); foreach (Device dev in assignedDevices){ if (dev is SmartPhone){ lines.Add(dev.GetDetails()); } } lines.Add("Wearables"); lines.Add("-"); foreach (Device dev in assignedDevices){ if (!(dev is SmartPhone)){ lines.Add(dev.GetDetails()); } } int phoneCount = 0; int wearableCount = 0; foreach (Device dev in assignedDevices){ if (dev is SmartPhone){ phoneCount++; } if (dev is IWearable){ wearableCount++; } } lines.Add("Total: " + assignedDevices.Count + " devices, " + phoneCount + " phones and " + wearableCount + " wearables"); return lines; } // -----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; } } }