예제 #1
0
        /// <summary>
        /// Prompts the user to select a unit choice
        /// from one unit to another
        /// </summary>
        private DistanceUnits SelectUnit(string prompt)
        {
            Console.WriteLine(prompt);

            string[] choices = { $" {DistanceUnits.Feet}",
                                 $" {DistanceUnits.Metres}",
                                 $" {DistanceUnits.Miles}" };

            int choice = ConsoleHelper.SelectChoice(choices);

            DistanceUnits unit;

            if (choice == 1)
            {
                unit = DistanceUnits.Feet;
            }
            else if (choice == 2)
            {
                unit = DistanceUnits.Metres;
            }
            else
            {
                unit = DistanceUnits.Miles;
            }

            Console.WriteLine($"\n You have selected {unit}");
            Console.WriteLine();

            return(unit);
        }
예제 #2
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();
        }
예제 #3
0
        /// <summary>
        /// Gets the units from inputs to see
        /// what they are measured from and to
        /// </summary>
        public void GetUnit()
        {
            Console.WriteLine(" Please Enter 2 different Distance Units" +
                              " to measure from and to");

            FromUnit = Distance.ElementAt(ConsoleHelper.SelectChoice(" Please select the from distance unit \n", Measurement) - 1).Key;
            ToUnit   = Distance.ElementAt(ConsoleHelper.SelectChoice(" Please select the to distance unit \n", Measurement) - 1).Key;
        }
        /// <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();
        }
        /// <summary>
        /// Shows the unit choices to the user.
        /// </summary>
        /// <param name="prompt">Prompts the user to enter a choice for the distance unit.</param>
        /// <returns>The user's selected choice.</returns>
        private int ShowChoices(string prompt)
        {
            Console.WriteLine("\t" + prompt);

            string[] choices = { $"\t{DistanceUnits.Miles}",
                                 $"\t{DistanceUnits.Feet}",
                                 $"\t{DistanceUnits.Metres}" };

            int choice = ConsoleHelper.SelectChoice(choices);

            return(choice);
        }
예제 #6
0
        /// <summary>
        /// Prompt the user to select their chosen (choices)unit
        /// </summary>
        /// <param name="prompt"> the user choice</param>
        /// <returns>the unit of the user choice</returns>
        private DistanceUnits SelectUnit(string prompt)
        {
            string[] choices =
            {
                DistanceUnits.Feet.ToString(),
                DistanceUnits.Metres.ToString(),
                DistanceUnits.Miles.ToString()
            };
            Console.WriteLine(prompt);
            int choiceNo = ConsoleHelper.SelectChoice(choices);

            return(ExecuteUnit(choiceNo));
        }
예제 #7
0
        ///<summary>
        /// Method calls methods to run the distance converter.
        ///</summary>
        public void run()
        {
            ConsoleHelper.OutputTitle();

            ConsoleHelper.OutputHeadingFrom();
            ConsoleHelper.DisplayChoices();
            FromUnit = ConsoleHelper.SelectChoice();

            ConsoleHelper.OutputHeadingTo();
            ConsoleHelper.DisplayChoices();
            ToUnit = ConsoleHelper.SelectChoice();

            FromDistance = ConsoleHelper.getDistance(FromUnit);

            CalculateDistance();

            ConsoleHelper.OutputResult(FromDistance, FromUnit, ToDistance, ToUnit);
        }
예제 #8
0
        private string SelectUnit(string prompt)
        {
            string [] choices =
            {
                FEET,
                METRES,
                MILES
            };
            Console.WriteLine(prompt);
            int choiceNo = ConsoleHelper.SelectChoice(choices);

            string unit = choices[choiceNo - 1];

            if (unit == null)
            {
                Console.WriteLine("error");
            }
            else
            {
                Console.WriteLine($"\n You have selected {unit}");
            }
            return(unit);
        }
예제 #9
0
        public static void Main()
        {
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("BNU CO453 Applications Programming 2020-2021!");
            Console.WriteLine("    Vincent Assolutissimamente 21905331");

            string[] choices  = { "Distance Converter", "BMI Calculator", "Student Grades", "Social Network", "RPG Game", "RockScissors", "Quit" };
            bool     finished = false;

            do
            {
                Console.WriteLine();
                Console.Beep();
                Console.WriteLine("What would you like to do next?");
                Console.WriteLine("");

                switch (ConsoleHelper.SelectChoice(choices))
                {
                case 1:
                {
                    DistanceConverter converter = new DistanceConverter();
                    ConsoleHelper.OutputHeading("Distance Converter");
                    converter.Convert();
                    break;
                }

                case 2:
                {
                    BMICalculator bmi = new BMICalculator();
                    ConsoleHelper.OutputHeading("BMI Calculator");
                    bmi.CalculateBMI();
                    break;
                }

                case 3:
                {
                    StudentGrades studentGrades = new StudentGrades();
                    ConsoleHelper.OutputHeading("Student Grades");
                    studentGrades.Main();
                    break;
                }

                case 4:
                {
                    NetworkApp app04 = new NetworkApp();
                    app04.DisplayMenu();
                    break;
                }

                case 5:     //RPG Game
                    break;

                case 6: GameImager Imager = new GameImager();
                    Imager.Menu();
                    break;

                case 7:
                    Console.WriteLine("Thank you and Goodbye!");
                    finished = true;
                    break;
                }
            } while (!finished);
        }
 /// <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 > ");
 }