Пример #1
0
        static void Main(string[] args)
        {
            var express  = new TransportShip("Planet Express", 10);
            var nostromo = new TransportShip("Nostromo", 50);

            // keep loading the Nostromo with eggs until there is not enough space left
            while (true)
            {
                var cargo = new Cargo("Crate with strange eggs", 4);

                if (!nostromo.AddCargo(cargo))
                {
                    break;
                }
            }

            Console.WriteLine($"{nostromo.Name}, space available: {nostromo.Available}");
            Console.WriteLine("- Moving some cargo to Planet Express...");

            // move as much as possible (2 items = 8 units of space) to the Planet Express
            nostromo.MoveCargoToOtherShip(express);

            Console.WriteLine($"{nostromo.Name}, space available: {nostromo.Available}");
            Console.WriteLine($"{express.Name}, space available: {express.Available}");

            express.ListCargo();
        }
Пример #2
0
        public bool MoveCargoToOtherShip(TransportShip ship)
        {
            while (storage.Count > 0)
            {
                if (ship.Available < storage.Peek().Size)
                {
                    return(false);
                }

                var item = RemoveCargo();

                ship.AddCargo(item);
            }

            return(true);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var ship = new TransportShip("Planet Express", 10);

            while (true)
            {
                var cargo = new Cargo("Bottles of Slurm", 3);

                if (!ship.AddCargo(cargo))
                {
                    break;
                }
            }

            Console.WriteLine($"{ship.Name}, space available: {ship.Available}");
            ship.ListCargo();

            ship.RemoveCargo();

            Console.WriteLine($"{ship.Name}, space available: {ship.Available}");
            ship.ListCargo();
        }