Esempio n. 1
0
        public static void Main()
        {
            List <Box> boxesList = new List <Box>();

            string input = Console.ReadLine();

            while (!input.Equals("end"))
            {
                string[] inputParts = input.Split(" :|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                Box currentBox = new Box();

                currentBox.upperLeft   = ReadPoint(int.Parse(inputParts[0]), int.Parse(inputParts[1]));
                currentBox.upperRight  = ReadPoint(int.Parse(inputParts[2]), int.Parse(inputParts[3]));
                currentBox.bottomLeft  = ReadPoint(int.Parse(inputParts[4]), int.Parse(inputParts[5]));
                currentBox.bottomRight = ReadPoint(int.Parse(inputParts[6]), int.Parse(inputParts[7]));

                boxesList.Add(currentBox);

                input = Console.ReadLine();
            }

            foreach (var box in boxesList)
            {
                double width  = Point.CalculateDistance(box.upperLeft, box.upperRight);
                double height = Point.CalculateDistance(box.upperLeft, box.bottomLeft);

                Console.WriteLine($"Box: {width}, {height}");
                Console.WriteLine($"Perimeter: {Box.CalculatePerimeter((int)width, (int)height)}");
                Console.WriteLine($"Area: {Box.CalculateArea((int)width, (int)height)}");
            }
        }
Esempio n. 2
0
        static void Main()
        {
            var boxesList = new List <Box>();
            var line      = Console.ReadLine();

            while (line != "end")
            {
                var input = line.Split(new char[] { ':', '|', ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var currentBox = new Box();
                currentBox.UpperLeft   = ReadPoint(input[0], input[1]);
                currentBox.UpperRight  = ReadPoint(input[2], input[3]);
                currentBox.BottomLeft  = ReadPoint(input[4], input[5]);
                currentBox.BottomRight = ReadPoint(input[6], input[7]);

                boxesList.Add(currentBox);

                line = Console.ReadLine();
            }

            //Print result
            foreach (var box in boxesList)
            {
                var width  = Point.CalculateDistance(box.UpperLeft, box.UpperRight);
                var height = Point.CalculateDistance(box.UpperLeft, box.BottomLeft);

                Console.WriteLine("Box: {0}, {1}", width, height);
                Console.WriteLine("Perimeter: {0}", Box.CalculatePerimeter((int)width, (int)height));
                Console.WriteLine("Area: {0}", Box.CalculateArea((int)width, (int)height));
            }
        }
        public static void Main()
        {
            var inputLine = Console.ReadLine();
            var boxes     = new List <Box>();

            while (inputLine != "end")
            {
                var inputLineParams = inputLine.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                var firstPoint  = Point.Parse(inputLineParams[0]);
                var secondPoint = Point.Parse(inputLineParams[1]);
                var thirdPoint  = Point.Parse(inputLineParams[2]);
                var fourthPoint = Point.Parse(inputLineParams[3]);

                var currentBox = Box.Parse(firstPoint, secondPoint, thirdPoint, fourthPoint);
                boxes.Add(currentBox);

                inputLine = Console.ReadLine();
            }

            foreach (var box in boxes)
            {
                var perimter = Box.CalculatePerimeter(box.Width, box.Height);
                var area     = Box.CalculateArea(box.Width, box.Height);

                Console.WriteLine($"Box: {box.Width}, {box.Height}");
                Console.WriteLine($"Perimeter: {perimter}");
                Console.WriteLine($"Area: {area}");
            }
        }
        static void Main()
        {
            var inputLine  = Console.ReadLine();
            var rectangles = new List <Point>();
            var result     = new List <Box>();

            while (inputLine != "end")

            {
                var splittedInput  = inputLine.Split(new[] { ' ', '|', ':' }, StringSplitOptions.RemoveEmptyEntries);
                var UpperLeftPoint = new Point
                {
                    X = int.Parse(splittedInput[0]),
                    Y = int.Parse(splittedInput[1])
                };

                var UpperRightPoint = new Point
                {
                    X = int.Parse(splittedInput[2]),
                    Y = int.Parse(splittedInput[3])
                };

                var BottomLeftPoint = new Point
                {
                    X = int.Parse(splittedInput[4]),
                    Y = int.Parse(splittedInput[5])
                };

                var BottomRightPoint = new Point
                {
                    X = int.Parse(splittedInput[6]),
                    Y = int.Parse(splittedInput[7])
                };


                var newObject = new Box
                {
                    UpperLeft   = UpperLeftPoint,
                    UpperRight  = UpperRightPoint,
                    BottomLeft  = BottomLeftPoint,
                    BottomRight = BottomRightPoint
                };
                result.Add(newObject);
                inputLine = Console.ReadLine();
            }
            foreach (var element in result)
            {
                int width  = (int)(element.Width);
                int height = (int)(element.Height);

                Console.WriteLine($"Box: {width}, {height}");
                Console.WriteLine($"Perimeter: {Box.CalculatePerimeter(width, height)}");
                Console.WriteLine($"Area: {Box.CalculateArea(width, height)}");
            }
        }
Esempio n. 5
0
        private static void PrintBoxes(List <Box> boxes)
        {
            foreach (Box box in boxes)
            {
                int width     = (int)Point.CalculateDistance(box.UpperLeft, box.UpperRight);
                int height    = (int)Point.CalculateDistance(box.UpperLeft, box.BottomLeft);
                int perimeter = Box.CalculatePerimeter(width, height);
                int area      = Box.CalculateArea(width, height);

                Console.WriteLine($"Box: {width}, {height}");
                Console.WriteLine($"Perimeter: {perimeter}");
                Console.WriteLine($"Area: {area}");
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            while (input != "end")
            {
                Box box = Box.ReadBox(input);

                Console.WriteLine($"Box: {box.Width}, {box.Height}");
                Console.WriteLine($"Perimeter: {Box.CalculatePerimeter(box.Width, box.Height)}");
                Console.WriteLine($"Area: {Box.CalculateArea(box.Width, box.Height)}");

                input = Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            List <Box> boxes = new List <Box>();
            string     input = Console.ReadLine();

            while (input != "end")
            {
                int[] tokens = input.Split(new string[] { " | ", ":" }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                boxes.Add(new Box()
                {
                    UpperLeft = new Point()
                    {
                        X = tokens[0],
                        Y = tokens[1]
                    },
                    UpperRight = new Point()
                    {
                        X = tokens[2],
                        Y = tokens[3]
                    },
                    BottomLeft = new Point()
                    {
                        X = tokens[4],
                        Y = tokens[5]
                    },
                    BottomRight = new Point()
                    {
                        X = tokens[4],
                        Y = tokens[5]
                    }
                });

                input = Console.ReadLine();
            }

            for (int i = 0; i < boxes.Count; i++)
            {
                Box currentBox = boxes[i];

                currentBox.Width  = (int)currentBox.UpperLeft.ReturnDistance(currentBox.UpperRight);
                currentBox.Height = (int)currentBox.UpperLeft.ReturnDistance(currentBox.BottomLeft);

                Console.WriteLine($"Box: {currentBox.Width}, {currentBox.Height}");
                Console.WriteLine($"Perimeter: {currentBox.CalculatePerimeter()}");
                Console.WriteLine($"Area: {currentBox.CalculateArea()}");
            }
        }