Exemple #1
0
        /**********************************************************************************************
        *  Function:       CalcResults()
        *  Description:    Calculates the results given a Fence object and returns a List of FenceResults
        *  Input:          myFence - the Fence object to calculate results from
        *  Output:         results - the List of FenceResults returned with calculated spacing and
        *                              measurements
        **********************************************************************************************/
        public static List <FenceResults> CalcResults(Fence myFence, double roundedTo)
        {
            int    numPickets   = 0;
            double spacing      = 0.0;
            double sectionWidth = 0.0;

            //make a list to return
            List <FenceResults> results = new List <FenceResults>();

            //calculate the number of pickets
            numPickets = FenceMath.GetNumPickets(myFence);

            //if no pickets, return no pickets fit
            if (numPickets > 0)
            {
                //calculate spacing rounded to double accuracy
                spacing = FenceMath.GetSpacing(myFence, numPickets);

                //calculate section width (spacing + picket width)
                sectionWidth = myFence.PicketWidth + spacing;

                //Console.Write("\nAll measurements are in inches and starting at the left edge of the workspace rounded to the nearest 1/16th\n");

                //put fence object into results list to return
                for (int i = 1; i <= numPickets; i++)
                {
                    FenceResults fence = new FenceResults(i, Calculations.DecimalToFraction(spacing, roundedTo).ToString(), spacing);
                    results.Add(fence);
                    spacing = spacing + sectionWidth;
                }
            }

            return(results);
        }
Exemple #2
0
        /**********************************************************************************************
        *  Function:       Main()
        *  Description:
        *  Input:
        *  Output:
        **********************************************************************************************/
        static void Main(string[] args)
        {
            double accuracy = 0.0;
            string frac;
            Fence  myFence = new Fence();       //new fence object

            //get wall length of the fence that pickets will go on
            Console.Write("Enter the Length of the Space to place pickets (in inches as 2-1/4 or 2.25): ");
            myFence.WallLength = GetInput(Console.ReadLine());

            //get picket width from user
            Console.Write("Enter the Width of the pickets (in inches as 1-1/8 or 1.125): ");
            myFence.PicketWidth = GetInput(Console.ReadLine());

            //get max space from the user between pickets
            Console.Write("Enter the Max Spacing between pickets (in inches as 4-1/2 or 4.5): ");
            myFence.MaxSpace = GetInput(Console.ReadLine());

            //get answers rounded to what place?
            Console.Write("Enter what you want answers rounded (in inches as 1/16 or 1/4): ");

            //store input as string to display for testing                                                                      //TEST
            //bypass to accuracy if not displayed                                                                               //TEST
            frac = Console.ReadLine();

            //combine above statement with this when working properly                                                           //TEST
            accuracy = GetInput(frac);

            //output info to console for verification
            Console.WriteLine("\nFence Length rounded to the nearest " + frac + ": \t" +
                              Calculations.DecimalToFraction(myFence.WallLength, accuracy) + '"');                              //TEST
            Console.WriteLine("Picket Width rounded to the nearest " + frac + ": \t" +
                              Calculations.DecimalToFraction(myFence.PicketWidth, accuracy) + '"');                             //TEST
            Console.WriteLine("Max Spacing rounded to the nearest  " + frac + ": \t" +
                              Calculations.DecimalToFraction(myFence.MaxSpace, accuracy) + '"');                                //TEST

            List <FenceResults> results = FenceMath.CalcResults(myFence, accuracy);

            if (results.Count == 0)
            {
                Console.WriteLine("No Pickets will fit in desired space!  Make sure the right measurements were entered and try again");
            }
            else
            {
                foreach (FenceResults r in results)
                {
                    Console.Write("\nLeft edge of picket " + r.boardNumber + " is at: \t" + r.roundedResult + '"');
                    Console.Write("     \t | Exact measurement is: " + r.exactResult);                                          //TEST
                }
            }

            Console.ReadLine();
        }