public Deliverable FindHeaviestDeliverable() { if (myDeliverables.Count == 0) { throw new Exception("There is no heaviest deliverable in an empty transport!"); } Deliverable heaviest = myDeliverables[0]; foreach (Deliverable d in myDeliverables) { if (d.Weight >= heaviest.Weight) { heaviest = d; } } // To do: // Was the conditional above a good solution? // Should it perhaps be instead one of the following: // if (d.Weight >= heaviest.Weight) // if (d.Weight < heaviest.Weight) // if (d.Weight > heaviest.Weight) return(heaviest); }
public void AddDeliverable(Deliverable d) { if (FindDeliverable(d.ID) == null) { myDeliverables.Add(d); } else { throw new Exception("Be aware: nothing is added!!!"); } }