Example #1
0
        public static WareHouse AddBox(WareHouse facility)
        {
            Console.WriteLine("Do you want to add the box to a specific location?\n(1): Yes\n(2): No\n");
            bool addToLocation = int.TryParse(Console.ReadLine(), out int input);

            int[] location = new int[2];
            if (addToLocation && input == 1)
            {
                location = GetLocation();
            }
            else if (addToLocation && input < 1 || input > 2)
            {
                Console.WriteLine("Incorrect input");
                return(facility);
            }
            else if (!addToLocation)
            {
                Console.WriteLine("Incorrect input");
                return(facility);
            }

            Console.WriteLine("Choose the shape of the packet: \n(1): Cube\n(2): CubeOid\n(3): Blob\n(4): Sphere");
            bool     menuInput = int.TryParse(Console.ReadLine(), out int shapeInput);
            BoxSpecs box       = new BoxSpecs();

            switch (shapeInput)
            {
            case 1:
            {
                box = BoxCreator("Cube");
                break;
            }

            case 2:
            {
                box = BoxCreator("CubeOid");
                break;
            }

            case 3:
            {
                box = BoxCreator("Blob");
                break;
            }

            case 4:
            {
                box = BoxCreator("Sphere");
                break;
            }

            default:
                Console.WriteLine("Incorrec input");
                return(facility);
            }
            if (box.Weight == 0 || box.XLength == 0)
            {
                Console.WriteLine("Couldnt add box due to error in user input");
            }
            else
            {
                int boxId = facility.Add(box, location[0], location[1]);

                if (boxId == -1)
                {
                    Console.WriteLine("Box could not be added, storage space is full or contains fragile box");
                }
                else
                {
                    Console.WriteLine("Box was added succesfully. Box Id: {0}", boxId);
                }
            }
            Console.ReadKey();
            return(facility);
        }
Example #2
0
        private static BoxSpecs BoxCreator(string description)
        {
            BoxSpecs box = new BoxSpecs();

            switch (description)
            {
            case "Cube":
            {
                Console.Write("Input dimensions\nSide length(cm):");
                bool correctLength = int.TryParse(Console.ReadLine(), out int length);
                Console.Write("Weight(kg): ");
                bool correctWeight = decimal.TryParse(Console.ReadLine(), out decimal weight);
                Console.Write("Is the packet fragile?\n(1): Yes (2): No\n");
                bool correctInput = int.TryParse(Console.ReadLine(), out int input);

                if (correctInput && correctLength && correctWeight)
                {
                    bool isFragile = input == 1 ? true : false;
                    box = new BoxSpecs(length, (decimal)weight, description, isFragile, 0);
                }
                else
                {
                    Console.WriteLine("Incorrect measurements");
                    return(box);
                }
                break;
            }

            case "CubeOid":
            {
                Console.Write("Input dimensions\nSide X length(cm):");
                bool correctXLength = int.TryParse(Console.ReadLine(), out int xlength);
                Console.Write("Input dimensions\nSide Y length(cm):");
                bool correctYLength = int.TryParse(Console.ReadLine(), out int ylength);
                Console.Write("Input dimensions\nSide Z length(cm):");
                bool correctZLength = int.TryParse(Console.ReadLine(), out int zlength);
                Console.Write("Weight(kg): ");
                bool correctWeight = decimal.TryParse(Console.ReadLine(), out decimal weight);
                Console.Write("Is the packet fragile?\n(1): Yes (2): No");
                bool correctInput = int.TryParse(Console.ReadLine(), out int input);

                if (correctInput && correctXLength && correctYLength && correctZLength && correctWeight)
                {
                    bool isFragile = input == 1 ? true : false;
                    box = new BoxSpecs(xlength, ylength, zlength, weight, description, isFragile, 0);
                }
                else
                {
                    Console.WriteLine("Incorrect measurements");
                    return(box);
                }
                break;
            }

            case "Blob":
            {
                Console.Write("Input dimensions\nSide length(cm):");
                bool correctLength = int.TryParse(Console.ReadLine(), out int length);
                Console.Write("Weight(kg): ");
                bool correctWeight = decimal.TryParse(Console.ReadLine(), out decimal weight);

                if (correctLength && correctWeight)
                {
                    box = new BoxSpecs(length, weight, description, true, 0);
                }
                else
                {
                    Console.WriteLine("Incorrect measurements");
                    return(box);
                }
                break;
            }

            case "Sphere":
            {
                Console.Write("Input dimensions\nRadius length(cm):");
                bool correctLength = int.TryParse(Console.ReadLine(), out int length);
                Console.Write("Weight(kg): ");
                bool correctWeight = decimal.TryParse(Console.ReadLine(), out decimal weight);
                Console.Write("Is the packet fragile?\n(1): Yes (2): No");
                bool correctInput = int.TryParse(Console.ReadLine(), out int input);

                if (correctInput && correctLength && correctWeight)
                {
                    bool isFragile = input == 1 ? true : false;
                    box = new BoxSpecs(length, weight, description, isFragile, 0);
                }
                else
                {
                    Console.WriteLine("Incorrect measurements");
                    return(box);
                }
                break;
            }
            }
            return(box);
        }