/// <summary> /// Removes a object from the boat stack /// </summary> /// <param name="removeObject">Object. Object to be removed</param> public Transportable removeBoat() { if (isEmpty()) { Console.WriteLine("The boat is empty"); return(null); } else { Transportable temp = inBoat.Pop(); Console.WriteLine(temp.Name + " was removed from the boat. It is now on the " + this.Side); seatsTaken--; return(temp); } }
/// <summary> /// Adds a object to the boat stack. /// </summary> /// <param name="AddObject">Object. The thing to be added</param> public void addBoat(Transportable AddObject) { if (AddObject.Side.Equals(this.Side)) { if (isEmpty()) { if (AddObject is Farmer) { inBoat.Push(AddObject); Console.WriteLine("The farmer gets in."); seatsTaken++; } else { Console.WriteLine("The farmer must get in first!"); } } else if (isFull()) { Console.WriteLine("The boat is full"); } else { if ((inBoat.Peek() is Farmer) && (AddObject is Farmer)) { Console.WriteLine("The farmer is already in the boat!"); } else { inBoat.Push(AddObject); Console.WriteLine(AddObject.Name + " gets in the boat."); seatsTaken++; } } } else { Console.WriteLine("They must be on the same side!"); } }