public bool TransferCargoFrom(BetterSpaceship otherShip) { if (otherShip.GetCargoSize() <= 0 || otherShip.GetCargoSize() > _free) { return(false); } Console.WriteLine("Transfering cargo from {0} to {1}", otherShip.Name, this.Name); _content += !String.IsNullOrEmpty(_content) ? "\n" + otherShip.GetContents() : otherShip.GetContents(); _free -= otherShip.GetCargoSize(); otherShip.Empty(); return(true); }
static void Four() { var condor = new BetterSpaceship() { Name = "Condor class transport ship 1", }; condor.SetSize(25); condor.AddCargo(new Cargo { Name = "Five thousand Marines", Size = 15 }); condor.AddCargo(new Cargo { Name = "Ammunition", Size = 3 }); condor.GetInfo(); var condor2 = new BetterSpaceship() { Name = "Condor class transport ship 2", }; condor2.SetSize(25); condor2.AddCargo(new Cargo { Name = "Ammunition", Size = 3 }); condor2.AddCargo(new Cargo { Name = "Ammunition", Size = 3 }); condor2.GetInfo(); Console.WriteLine(); condor2.TransferCargoFrom(condor); condor.GetInfo(); Console.WriteLine(); Console.WriteLine(); condor2.GetInfo(); }
static void Three() { var condor = new BetterSpaceship() { Name = "Condor class transport ship 1", }; condor.SetSize(25); condor.AddCargo(new Cargo { Name = "Five thousand Marines", Size = 15 }); condor.AddCargo(new Cargo { Name = "Ammunition", Size = 3 }); condor.GetInfo(); Console.WriteLine("Cargo size = {0}", condor.GetCargoSize()); Console.WriteLine(); Console.WriteLine("Dumping cargo!"); Console.WriteLine(); condor.Empty(); condor.GetInfo(); }