示例#1
0
        public static RoomResults CalculateCustomResults(List <double[]> coords, double perimeter, double height, List <double[]> windows)
        {
            // Calculate Floor Area
            // Area from Shoelace Algorithm
            double floorArea = 0;
            int    lastPoint = coords.Count - 1;

            for (int i = 0; i < coords.Count; i++)
            {
                floorArea += ((coords[lastPoint][0] + coords[i][0]) * (coords[lastPoint][1] - coords[i][1])) / 2;
                lastPoint  = i;
            }
            floorArea = Math.Abs(floorArea);

            // Calculate Volume of Paint Needed
            // Note: Based on 1 litre per 10 square metres
            double wallArea   = height * perimeter;
            double windowArea = 0;

            for (int i = 0; i < windows.Count; i++)
            {
                windowArea += (windows[i][0] * windows[i][1]);
            }
            double paintVolume = (wallArea - windowArea) * 0.1;

            // Calculate Room Volume
            // Volume = Width x Depth x Height
            double roomVolume = floorArea * height;

            RoomResults results = new RoomResults(floorArea, paintVolume, roomVolume);

            return(results);
        }
示例#2
0
        public static RoomResults CalculateResults(double width, double depth, double height, List <double[]> windows)
        {
            // Calculate Floor Area
            // Area = Width x Depth
            double floorArea = width * depth;

            // Calculate Volume of Paint Needed
            // Note: Based on 1 litre per 10 square metres
            double wallArea   = 2 * height * (width + depth);
            double windowArea = 0;

            for (int i = 0; i < windows.Count; i++)
            {
                windowArea += (windows[i][0] * windows[i][1]);
            }
            double paintVolume = (wallArea - windowArea) * 0.1;

            // Calculate Room Volume
            // Volume = Width x Depth x Height
            double roomVolume = width * depth * height;

            RoomResults results = new RoomResults(floorArea, paintVolume, roomVolume);

            return(results);
        }
        public static RoomResults CalculateResults(double width, double depth, double height)
        {
            // Calculate Floor Area
            // Area = Width x Depth
            double floorArea = width * depth;

            // Calculate Volume of Paint Needed
            // Note: Based on 1 litre per 10 square metres
            double wallArea    = 2 * height * (width + depth);
            double paintVolume = wallArea * 0.1;

            // Calculate Room Volume
            // Volume = Width x Depth x Height
            double roomVolume = width * depth * height;

            RoomResults results = new RoomResults(floorArea, paintVolume, roomVolume);

            return(results);
        }
        public static void Main()
        {
            // Outputs Needed:
            // 1. Area of the floor
            // 2. Amount of paint required to paint the walls
            // 3. Volume of the room

startProgram:

            string userInputWidth, userInputDepth, userInputHeight, userResponse;
            double width, depth, height;

            Console.WriteLine("**** Borwell Software Challenge v1.0 ****");
            Console.WriteLine("**** Basic Rectangular Room ****");
            Console.WriteLine();

            // Get & Check User Input for Width
roomWidth:
            Console.WriteLine("Enter Room Width (in metres):");
            userInputWidth = Console.ReadLine();
            if (!CheckInput(userInputWidth))
            {
                goto roomWidth;
            }
            else
            {
                double.TryParse(userInputWidth, out width);
            }

            // Get & Check User Input for Depth
roomDepth:
            Console.WriteLine("Enter Room Depth (in metres):");
            userInputDepth = Console.ReadLine();
            if (!CheckInput(userInputDepth))
            {
                goto roomDepth;
            }
            else
            {
                double.TryParse(userInputDepth, out depth);
            }

            // Get & Check User Input for Height
roomHeight:
            Console.WriteLine("Enter Room Height (in metres):");
            userInputHeight = Console.ReadLine();
            if (!CheckInput(userInputHeight))
            {
                goto roomHeight;
            }
            else
            {
                double.TryParse(userInputHeight, out height);
            }

            // Get Calculation Results
            RoomResults calcResults = CalculateResults(width, depth, height);

            Console.WriteLine($"*** Results *** \r\n" +
                              $"Based on these dimensions: \r\n" +
                              $"Width: {width} m, Depth: {depth} m, Height: {height} m \r\n\r\n" +
                              $"1. Floor Area: {calcResults.FloorArea} m^2 \r\n" +
                              $"2. Volume of Paint Needed to Cover Walls: {calcResults.PaintVolume} litres \r\n" +
                              $"3. Volume of Room: {calcResults.RoomVolume} m^3 \r\n\r\n");

            Console.WriteLine("Enter 'R' to restart, or any other key to end program.");

            userResponse = Console.ReadLine();
            if (userResponse.ToUpper() == "R")
            {
                goto startProgram;
            }
            else
            {
                return;
            }
        }
示例#5
0
        public static void Main(string[] args)
        {
            // Outputs Needed:
            // 1. Area of the floor
            // 2. Amount of paint required to paint the walls
            // 3. Volume of the room

startProgram:

            string userInputWidth, userInputDepth, userInputHeight, userInputWindow, userResponse, userType, userInputCoord;
            double          width, depth, height, perimeter = 0;
            bool            rectangular;
            List <double[]> coordList = new List <double[]>();

            Console.WriteLine("**** Borwell Software Challenge v3.0 ****");
            Console.WriteLine("**** Basic Rectangular Room / Custom Shape Room with Windows/Doors ****");
            Console.WriteLine();

getRoomType:
            Console.WriteLine("Enter 'R' for Rectangular Room, Enter 'C' for Custom Room, Enter 'X' to Exit Program:");
            userType = Console.ReadLine();
            if (userType.ToUpper() == "R")
            {
                rectangular = true;
            }
            else if (userType.ToUpper() == "C")
            {
                rectangular = false;
            }
            else if (userType.ToUpper() == "X")
            {
                return;
            }
            else
            {
                goto getRoomType;
            }

            if (rectangular)
            {
                // Get & Check User Input for Width
roomWidth:
                Console.WriteLine("Enter Room Width (in metres):");
                userInputWidth = Console.ReadLine();
                if (!CheckInput(userInputWidth))
                {
                    goto roomWidth;
                }
                else
                {
                    double.TryParse(userInputWidth, out width);
                }

                // Get & Check User Input for Depth
roomDepth:
                Console.WriteLine("Enter Room Depth (in metres):");
                userInputDepth = Console.ReadLine();
                if (!CheckInput(userInputDepth))
                {
                    goto roomDepth;
                }
                else
                {
                    double.TryParse(userInputDepth, out depth);
                }

                // Get & Check User Input for Height
roomHeight:
                Console.WriteLine("Enter Room Height (in metres):");
                userInputHeight = Console.ReadLine();
                if (!CheckInput(userInputHeight))
                {
                    goto roomHeight;
                }
                else
                {
                    double.TryParse(userInputHeight, out height);
                }
            }
            else
            {
                // Get & Check User Input for Room Coordinates
                coordList = new List <double[]>();
                Console.WriteLine("Enter coordinates of corners in room.\r\n" +
                                  "(e.g.)\r\n" +
                                  "0 0\r\n" +
                                  "0 3.5\r\n" +
                                  "4.5 6\r\n" +
                                  "4.5 0\r\n" +
                                  "F\r\n" +
                                  "Enter each in metres as X Y then enter 'F' when finished:");
coordInput:
                userInputCoord = Console.ReadLine();
                if (userInputCoord.ToUpper() != "F")
                {
                    CoordResults cr = CheckCoordInput(userInputCoord);
                    if (cr.ValidInput)
                    {
                        coordList.Add(cr.Coords);
                    }
                    goto coordInput;
                }
                else
                {
                    if (coordList.Count < 3)
                    {
                        Console.WriteLine("Room must have at least 3 corners.");
                        goto coordInput;
                    }
                }

                // Get & Check User Input for Height
roomHeightCustom:
                Console.WriteLine("Enter Room Height (in metres):");
                userInputHeight = Console.ReadLine();
                if (!CheckInput(userInputHeight))
                {
                    goto roomHeightCustom;
                }
                else
                {
                    double.TryParse(userInputHeight, out height);
                }

                // Calculate wall lengths
                double[] wallLengths = new double[coordList.Count];
                for (int i = 0; i < wallLengths.Length; i++)
                {
                    wallLengths[i] = Math.Sqrt(Math.Pow(coordList[(i + 1) % wallLengths.Length][0] - coordList[i][0], 2) + Math.Pow(coordList[(i + 1) % wallLengths.Length][1] - coordList[i][1], 2));
                }
                perimeter = wallLengths.Sum();
                width     = perimeter / 4;
                depth     = width;
            }

            // Get & Check User Input for Windows/Doors
            List <double[]> windowList = new List <double[]>();

            Console.WriteLine("Enter dimensions of windows/doors/areas not to be painted.\r\n" +
                              "(e.g.)\r\n" +
                              "0.7 1.2\r\n" +
                              "1.1 1.2\r\n" +
                              "1.5 2.2\r\n" +
                              "F\r\n" +
                              "Enter each in metres as WIDTH HEIGHT then enter 'F' when finished:");
windowInput:
            userInputWindow = Console.ReadLine();
            if (userInputWindow.ToUpper() != "F")
            {
                WindowResults wr = CheckWindowInput(userInputWindow, windowList, width, depth, height);
                if (wr.ValidInput)
                {
                    windowList.Add(wr.WindowDimensions);
                }
                goto windowInput;
            }

            string windowInfo = "";

            for (int i = 0; i < windowList.Count; i++)
            {
                windowInfo += $"{i + 1}. {windowList[i][0]} m x {windowList[i][1]} m\r\n";
            }
            if (windowInfo.Length == 0)
            {
                windowInfo = "None.";
            }

            if (rectangular)
            {
                // Get Calculation Results
                RoomResults calcResults = CalculateResults(width, depth, height, windowList);

                Console.WriteLine($"\r\n\r\n*** Results *** \r\n" +
                                  $"Based on these dimensions: \r\n" +
                                  $"Width: {width} m, Depth: {depth} m, Height: {height} m \r\n\r\n" +
                                  $"Windows:\r\n" + windowInfo + "\r\n" +
                                  $"1. Floor Area: {calcResults.FloorArea} m^2 \r\n" +
                                  $"2. Volume of Paint Needed to Cover Walls: {calcResults.PaintVolume} litres \r\n" +
                                  $"3. Volume of Room: {calcResults.RoomVolume} m^3 \r\n\r\n");
            }
            else
            {
                // Get Calculation Results
                RoomResults calcCustomResults = CalculateCustomResults(coordList, perimeter, height, windowList);

                string coordInfo = "";
                for (int i = 0; i < coordList.Count; i++)
                {
                    coordInfo += $"{i + 1}. ({coordList[i][0]}, {coordList[i][1]})\r\n";
                }

                Console.WriteLine($"\r\n\r\n*** Results *** \r\n" +
                                  $"Based on these coordinates: \r\n" +
                                  coordInfo +
                                  $"Windows:\r\n" + windowInfo + "\r\n" +
                                  $"1. Floor Area: {calcCustomResults.FloorArea} m^2 \r\n" +
                                  $"2. Volume of Paint Needed to Cover Walls: {calcCustomResults.PaintVolume} litres \r\n" +
                                  $"3. Volume of Room: {calcCustomResults.RoomVolume} m^3 \r\n\r\n");
            }

            Console.WriteLine("Enter 'R' to restart, or any other key to end program.");

            userResponse = Console.ReadLine();
            if (userResponse.ToUpper() == "R")
            {
                goto startProgram;
            }
            else
            {
                return;
            }
        }
示例#6
0
        public static void Main()
        {
            // Outputs Needed:
            // 1. Area of the floor
            // 2. Amount of paint required to paint the walls
            // 3. Volume of the room

startProgram:

            string userInputWidth, userInputDepth, userInputHeight, userInputWindow, userResponse;
            double width, depth, height;

            Console.WriteLine("**** Borwell Software Challenge v2.0 ****");
            Console.WriteLine("**** Basic Rectangular Room with Windows/Doors ****");
            Console.WriteLine();

            // Get & Check User Input for Width
roomWidth:
            Console.WriteLine("Enter Room Width (in metres):");
            userInputWidth = Console.ReadLine();
            if (!CheckInput(userInputWidth))
            {
                goto roomWidth;
            }
            else
            {
                double.TryParse(userInputWidth, out width);
            }

            // Get & Check User Input for Depth
roomDepth:
            Console.WriteLine("Enter Room Depth (in metres):");
            userInputDepth = Console.ReadLine();
            if (!CheckInput(userInputDepth))
            {
                goto roomDepth;
            }
            else
            {
                double.TryParse(userInputDepth, out depth);
            }

            // Get & Check User Input for Height
roomHeight:
            Console.WriteLine("Enter Room Height (in metres):");
            userInputHeight = Console.ReadLine();
            if (!CheckInput(userInputHeight))
            {
                goto roomHeight;
            }
            else
            {
                double.TryParse(userInputHeight, out height);
            }

            // Get & Check User Input for Windows/Doors
            List <double[]> windowList = new List <double[]>();

            Console.WriteLine("Enter dimensions of windows/doors/areas not to be painted.\r\n" +
                              "(e.g.)\r\n" +
                              "0.7 1.2\r\n" +
                              "1.1 1.2\r\n" +
                              "1.5 2.2\r\n" +
                              "F\r\n" +
                              "Enter each in metres as WIDTH HEIGHT then enter 'F' when finished:");
windowInput:
            userInputWindow = Console.ReadLine();
            if (userInputWindow.ToUpper() != "F")
            {
                WindowResults wr = CheckWindowInput(userInputWindow, windowList, width, depth, height);
                if (wr.ValidInput)
                {
                    windowList.Add(wr.WindowDimensions);
                }
                goto windowInput;
            }

            string windowInfo = "";

            for (int i = 0; i < windowList.Count; i++)
            {
                windowInfo += $"{i+1}. {windowList[i][0]} m x {windowList[i][1]} m\r\n";
            }
            if (windowInfo.Length == 0)
            {
                windowInfo = "None.";
            }

            // Get Calculation Results
            RoomResults calcResults = CalculateResults(width, depth, height, windowList);

            Console.WriteLine($"*** Results *** \r\n" +
                              $"Based on these dimensions: \r\n" +
                              $"Width: {width} m, Depth: {depth} m, Height: {height} m \r\n\r\n" +
                              $"Windows:\r\n" + windowInfo + "\r\n" +
                              $"1. Floor Area: {calcResults.FloorArea} m^2 \r\n" +
                              $"2. Volume of Paint Needed to Cover Walls: {calcResults.PaintVolume} litres \r\n" +
                              $"3. Volume of Room: {calcResults.RoomVolume} m^3 \r\n\r\n");

            Console.WriteLine("Enter 'R' to restart, or any other key to end program.");

            userResponse = Console.ReadLine();
            if (userResponse.ToUpper() == "R")
            {
                goto startProgram;
            }
            else
            {
                return;
            }
        }