GetWeight() public method

public GetWeight ( ) : float
return float
Example #1
0
        private bool CheckWeight(Container container, int width, int depth, int z)
        {
            int weight;

            for (int i = 0; i < ship.GetHeight(); i++)
            {
                weight = container.GetWeight();
                for (int height = i; height < ship.GetHeight(); height++)
                {
                    if (ship.GetContainer(width, depth, height) != null)
                    {
                        weight += ship.GetContainer(width, depth, height).GetWeight();
                    }
                }

                if (ship.GetContainer(width, depth, i) != null)
                {
                    weight -= ship.GetContainer(width, depth, i).GetWeight();
                }

                if (weight > 120)
                {
                    return(false);
                }

                weight = 0;
            }

            return(true);
        }
        public void GetWeight_ShouldGetWeightAsTwoDecimals()
        {
            //Arrange
            var expected = 15;
            //Act
            var actual = container.GetWeight();

            //Assert
            Assert.Equal(expected, actual);
        }
Example #3
0
        private bool PlaceContainer(Container container, int width, int depth)
        {
            for (int height = 0; height < ship.GetHeight(); height++)
            {
                if (ship.GetContainer(width, depth, height) != null)
                {
                    if (ship.GetContainer(width, depth, height).GetType() == TypeContainer.RefrigeratedValuable_Container || ship.GetContainer(width, depth, height).GetType() == TypeContainer.Valuable_Container)
                    {
                        Program.PrintError("ERR: VALUABLE");
                        return(false);
                    }

                    if (!CheckWeight(container, width, depth, height))
                    {
                        Program.PrintError("ERR: WEIGHT");
                        return(false);
                    }
                }

                if (ship.GetContainer(width, depth + 1, height) != null)
                {
                    if (ship.GetContainer(width, depth + 1, height).GetType() == TypeContainer.Valuable_Container || ship.GetContainer(width, depth + 1, height).GetType() == TypeContainer.RefrigeratedValuable_Container)
                    {
                        Program.PrintError("ERR: NEXT TO VALUABLE");
                        return(false);
                    }
                }
                if (ship.GetContainer(width, depth - 1, height) != null)
                {
                    if (ship.GetContainer(width, depth - 1, height).GetType() == TypeContainer.Valuable_Container || ship.GetContainer(width, depth - 1, height).GetType() == TypeContainer.RefrigeratedValuable_Container)
                    {
                        Program.PrintError("ERR: NEXT TO VALUABLE");
                        return(false);
                    }
                }



                if (ship.GetContainer(width, depth, height) == null)
                {
                    if (container.GetType() == TypeContainer.Valuable_Container || container.GetType() == TypeContainer.RefrigeratedValuable_Container)
                    {
                        if (ship.GetContainer(width, depth + 1, height) != null)
                        {
                            Program.PrintError("ERR: NEXT TO VALUABLE");
                        }
                        else if (ship.GetContainer(width, depth - 1, height) != null)
                        {
                            Program.PrintError("ERR: NEXT TO VALUABLE");
                        }
                    }


                    if (ship.AddToRow(container, width, depth, height))
                    {
                        Program.PrintMessage($"placed {container} at index: {width} {depth} {height} with a weight of: {container.GetWeight()}");
                        container.SetPlacedStatus(true);
                        container.SetIndex(height);
                        return(true);
                    }
                    else
                    {
                        Program.PrintError($"Could not place container at {width} {depth} {height}");
                    }
                }
            }
            Program.PrintError($"Could not place container at {width} {depth}");
            return(false);
        }