示例#1
0
        public void StartModernConveyor()
        {
            Boxes.Add(new Box());

            while (true)
            {
                double weight;

                Item item;
                if (Items.Count == 0)
                {
                    weight = FractionUI.EnterFraction();
                    item   = new Item(weight);
                }
                else
                {
                    item = new Item(Items[0].Weight);
                    Items.RemoveAt(0);
                }

                bool checkBox = false;
                foreach (var box in Boxes)
                {
                    checkBox = box.CheckCapacity(item);
                    if (checkBox)
                    {
                        box.PutItem(item);
                        break;
                    }
                }

                if (!checkBox)
                {
                    var box = new Box();
                    box.PutItem(item);
                    Boxes.Add(box);
                }

                foreach (var box in Boxes)
                {
                    Console.WriteLine(box.ToString());
                }
            }
        }
示例#2
0
        public void StartUsualConveyor()
        {
            Boxes.Add(new Box());
            var boxIndex = 0;

            while (true)
            {
                double weight;

                Item item;
                if (Items.Count == 0)
                {
                    weight = FractionUI.EnterFraction();
                    item   = new Item(weight);
                }
                else
                {
                    item = new Item(Items[0].Weight);
                    Items.RemoveAt(0);
                }

                bool check = Boxes[boxIndex].CheckCapacity(item);

                if (!check)
                {
                    Boxes.Add(new Box());
                    boxIndex++;
                }

                Boxes[boxIndex].PutItem(item);

                foreach (var box in Boxes)
                {
                    Console.WriteLine(box.ToString());
                }
            }
        }