Example #1
0
        /// <summary>
        /// This method outputs the heading and gives the user a choice
        /// of distance unit they would like to convert from and to.
        /// It lets the user know the distance is being converted, calculates
        /// the conversion and gives the user the result
        /// </summary>
        public void ConvertDistance()
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\n Selecting units");
            string[] choices = new string[]
            {
                FEET, METRES, MILES
            };

            Console.WriteLine($"\n Please select a unit to convert from\n");
            int choice = ConsoleHelper.SelectChoice(choices);

            FromUnit = choices[choice - 1];
            Console.WriteLine($"\n You have selected {FromUnit}! ");

            Console.WriteLine($"\n Please select a unit to convert to\n");
            choice = ConsoleHelper.SelectChoice(choices);
            ToUnit = choices[choice - 1];
            Console.WriteLine($"\n You have selected {ToUnit}! ");

            FromDistance = ConsoleHelper.InputNumber($"\n Please enter the number of" +
                                                     $" {FromUnit} you wish to convert to {ToUnit} > ");

            ConsoleHelper.OutputTitle($"\n Converting {FromUnit} to {ToUnit} ");
            CalculateDistance();

            OutputDistance();
        }
        /// <summary>
        /// Asks the user to input a distance, which is then converted into the unit
        /// they selected at the start, and the result is
        /// displayed on-screen.
        /// </summary>
        public void ConvertDistance()
        {
            ConsoleHelper.OutputHeading("Distance Conversion Calculator");

            FromUnit = SelectUnit("From Unit");
            ToUnit   = SelectUnit("To Unit");

            /// If the user has selected the From and To units with the same
            /// choice, an error message will appear and will keep doing so
            /// until they choose a different To unit.
            while (ToUnit == FromUnit)
            {
                Console.WriteLine("\tThe To unit cannot be the same as " +
                                  "the From unit. Please try again.\n");
                ToUnit = SelectUnit("To Unit");
            }

            Console.WriteLine($"\t{FromUnit} -> {ToUnit} Conversion");

            FromDistance = ConsoleHelper.InputNumber($"\tPlease enter the number of {FromUnit} > ");

            CalculateDistance();

            OutputDistance();

            ExitDecision();
        }
        /// <summary>
        /// This method will Input the distance in miles
        /// calculate the same distance in feet, and output the
        /// distance in feet.
        /// </summary>
        public void ConvertDistance()
        {
            string[] choices = new string[]
            {
                FEET, METERS, MILES
            };

            int choice;

            Console.WriteLine("Select the distance unit to convert from >");
            choice   = ConsoleHelper.SelectChoice(choices);
            FromUnit = ExecuteChoice(choice);

            if (choice == 1)
            {
                Console.WriteLine("You have selected Feet");
            }

            else if (choice == 2)
            {
                Console.WriteLine("You have selected Meters");
            }

            else if (choice == 3)
            {
                Console.WriteLine("You have selected Miles");
            }



            Console.WriteLine("Select the distance unit to convert to >");
            choice = ConsoleHelper.SelectChoice(choices);
            ToUnit = ExecuteChoice(choice);

            if (choice == 1)
            {
                Console.WriteLine("You have selected Feet");
            }

            else if (choice == 2)
            {
                Console.WriteLine("You have selected Meters");
            }

            else if (choice == 3)
            {
                Console.WriteLine("You have selected Miles");
            }

            ConsoleHelper.OutputHeading($"Converting {FromUnit} to {ToUnit}");

            FromDistance = ConsoleHelper.InputNumber($"Please enter the number of {FromUnit} > ");

            CalculateDistance();

            OutputDistance();
        }
Example #4
0
        /// <summary>
        /// Call other methods
        /// Prompts the user to input which unit the distance which will be converted from
        /// and which unit it will be converted to.
        /// </summary>
        public void ConvertDistance()
        {
            ConsoleHelper.OutputHeading("Distance Converter");

            FromUnit = SelectUnit("Please select the from distance unit > ");
            ToUnit   = SelectUnit("Please select the to distance unit > ");

            Console.WriteLine($"Converting {FromUnit} to {ToUnit}\n");

            FromDistance = ConsoleHelper.InputNumber($"Please enter the number of {FromUnit} > ");
            CalculateDistance();
            OutputDistance();
        }
Example #5
0
        /// <summary>
        /// Run Distance Converter App
        /// </summary>
        public void ConvertDistance()
        {
            // Distance Converter is output as heading
            ConsoleHelper.OutputHeading("Distance Converter");

            // This looks for and gets the Unit
            GetUnit();

            // Repeater checks if the ToUnit and FromUnit are the same.
            Repeater();

            Console.WriteLine($"\n Converting {FromUnit} to {ToUnit}");

            // Looks for an input to put into FromDistance to
            // convert the 2 different measurements
            FromDistance = (double)(UnitEnum)ConsoleHelper.InputNumber($"Please enter the" +
                                                                       $" number of {FromUnit} ");
            // Calculates the distance from the input recieved
            CalculateDistance();

            // Outputs result
            OutputDistance();
        }
 /// <summary>
 /// Values.ElementAt(index).key returns the key associated to the index number that the
 /// user will chose.
 /// </summary>
 public void GetValues()
 {
     FromValue = Values.ElementAt(ConsoleHelper.SelectChoice("Select your FROM unit from the list:", Units) - 1).Key;
     ToValue   = Values.ElementAt(ConsoleHelper.SelectChoice("Select your TO unit from the list:", Units) - 1).Key;
     Amount    = ConsoleHelper.InputNumber("Please enter an amount > ");
 }