/// <summary> /// Method to add sweet in present box /// </summary> /// <param name="sweet"></param> internal void AddSweets(Sweet sweet) { Sweets.Add(sweet); Weight += sweet.Weight; Volume += sweet.Volume; if (Overflow()) { throw new OverflowException("Present box can't accommodate so much sweets"); } }
/// <summary> /// Method to sort sweets in present box by weight in descending order /// </summary> internal void DescendingSortByWeight() { for (int i = 0; i <= Sweets.Count - 2; i++) { if (Sweets[i].Weight < Sweets[i + 1].Weight) { Sweet temp = Sweets[i]; Sweets[i] = Sweets[i + 1]; Sweets[i + 1] = temp; } } }
/// <summary> /// Method to remove sweet from present box /// </summary> /// <param name="sweet"></param> internal void RemoveSweets(Sweet sweet) { Weight -= sweet.Weight; Sweets.Remove(sweet); Volume -= sweet.Volume; }