コード例 #1
0
ファイル: Program.cs プロジェクト: jpzimmerman/BondJames
        static void Main(string[] args)
        {
            string      startingUserName = "", startingUserNameSwapped = "";
            YesNoAnswer userAnswer = YesNoAnswer.AnswerNotGiven;

            Console.Write("***********************************************************\n" +
                          "*               Dev.Build(2.0) - Bond James               *\n" +
                          "***********************************************************\n\n");

            while (true)
            {
                while (startingUserName.Trim() == "" || !startingUserName.Contains(' '))
                {
                    Console.Write("Please enter your first and last name: ");
                    startingUserName = Console.ReadLine().Trim();
                }
                startingUserNameSwapped = SwapNames(startingUserName);
                Console.WriteLine("Swapped name is {0}", startingUserNameSwapped);
                startingUserName = "";

                userAnswer = UserInput.GetYesOrNoAnswer("Do you wish to enter another name? (y/n or yes/no) ");
                switch (userAnswer)
                {
                case YesNoAnswer.Yes: userAnswer = YesNoAnswer.AnswerNotGiven; continue;

                case YesNoAnswer.No: userAnswer = YesNoAnswer.AnswerNotGiven; return;
                }
            }
        }
コード例 #2
0
 private static void DisplayAnswer(YesNoAnswer answer)
 {
     CustomConsole.WriteLine();
     CustomConsole.Write("Your answer: ");
     CustomConsole.WriteLineEmphasies(answer);
     CustomConsole.WriteLine();
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: jpzimmerman/Math_JPZ
        static void Main(string[] args)
        {
            int         userNumber = 0;
            YesNoAnswer userAnswer = YesNoAnswer.AnswerNotGiven;

            Console.Write("***********************************************************\n" +
                          "*          Dev.Build(2.0) - Multiplication Tables         *\n" +
                          "***********************************************************\n\n");
            while (true)
            {
                //Prompt user to enter number, verify that input was indeed a number
                Console.Write("Please enter a number: ");
                while (!int.TryParse(Console.ReadLine(), out userNumber))
                {
                    Console.Write("Please enter a number: ");
                }

                //Send user's number to PrintMultiplicationTable for display of multiples
                PrintMultiplicationTable(userNumber);

                //ask the user if they would like to enter another number
                userAnswer = UserInput.GetYesOrNoAnswer("Would you like to enter another number? ");
                switch (userAnswer)
                {
                case YesNoAnswer.Yes: userAnswer = YesNoAnswer.AnswerNotGiven; continue;

                case YesNoAnswer.No: userAnswer = YesNoAnswer.AnswerNotGiven; return;
                }
            }
        }
コード例 #4
0
        public IActionResult Create(YesNoAnswer yesNoAnswer)
        {
            if (ModelState.IsValid)
            {
                var questionId = yesNoAnswer.YesNoQuestionId;
                var pollId     = pollService.GetPollByQuestionId(questionId); // pollId
                if (pollId == -1)
                {
                    return(RedirectToAction(nameof(ErrorView)));
                }
                var      userName = User.Identity.Name;
                var      user     = userService.GetUserByUserName(userName); //userıd
                UserPoll userPoll = new UserPoll();
                userPoll.PollId = pollId;
                userPoll.UserId = user.Id;
                userSurveysService.Add(userPoll);


                yesNoAnswerService.AddYesNoAnswer(yesNoAnswer);

                bool IsApproved = pollService.IsApprovedPoll(pollId, questionId);
                return(RedirectToAction("ToBeVotedSurveys", "Voted"));
            }
            List <SelectListItem> selectListItems = GetQuestionForSelect();

            ViewBag.Items = selectListItems;
            return(RedirectToAction("ToBeVotedSurveys", "Voted"));
        }
コード例 #5
0
        static void Main(string[] args)
        {
            List <double> oddNumbers = new List <double>();

            while (true)
            {
                userResponse = "";
                oddNumbers.Clear();
                while (!uint.TryParse(userResponse, out maxRangeOfOddNumbers) || maxRangeOfOddNumbers < 1)
                {
                    UserInput.PromptUntilValidEntry("Please enter a number greater than zero: ", ref userResponse, InformationType.Numeric);
                }

                for (double i = 0; i <= maxRangeOfOddNumbers; i++)
                {
                    if (i % 2 == 1)
                    {
                        oddNumbers.Add(i);
                    }
                }
                Console.WriteLine($"The sum of all the odd numbers between 1 and {maxRangeOfOddNumbers} is {CalculateSum(oddNumbers)}");
                Console.WriteLine($"The average of all the odd numbers between 1 and {maxRangeOfOddNumbers} is {CalculateAverage(oddNumbers)}");

                maxRangeOfOddNumbers = 0;

                YesNoAnswer yesNoAnswer = UserInput.GetYesOrNoAnswer("Would you like to enter another maximum?");
                switch (yesNoAnswer)
                {
                case YesNoAnswer.Yes: continue;

                case YesNoAnswer.No: return;
                }
            }
        }
コード例 #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            YesNoAnswer yesNoAnswer = db.YesNoAnswers.Find(id);

            db.YesNoAnswers.Remove(yesNoAnswer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public void Execute()
        {
            CustomConsole.WriteLine("This is a simple yes/no control with no default value.");
            CustomConsole.WriteLine();

            YesNoAnswer answer = AskQuestion();

            DisplayAnswer(answer);
        }
コード例 #8
0
        public void Execute()
        {
            CustomConsole.WriteLine("This is a yes/no/cancel control with default value 'Yes'.");
            CustomConsole.WriteLine();

            YesNoAnswer answer = AskQuestion();

            DisplayAnswer(answer);
        }
コード例 #9
0
        static void Main(string[] args)
        {
            string      userInputString = "";
            YesNoAnswer userAnswer      = YesNoAnswer.AnswerNotGiven;

            Console.Write("***********************************************************\n" +
                          "*                  Dev.Build(2.0) - Pig Latin             *\n" +
                          "***********************************************************\n\n");

            //Greet the user
            Console.WriteLine("Welcome to the Pig Latin Translator!");

            while (true)
            {
                //Prompt the user for a word
                while (String.IsNullOrEmpty(userInputString))
                {
                    Console.Write("Enter a line to be translated: ");
                    userInputString = Console.ReadLine().Trim();
                }

                #region Check user's string for email address, phone number, etc.
                //Run data through all the regexes we have, just to see if user entered an email address, phone number, etc.
                if (Validation.ValidateInfo(InformationType.Numeric, userInputString) ||
                    Validation.ValidateInfo(InformationType.EmailAddress, userInputString) ||
                    Validation.ValidateInfo(InformationType.ContainsInvalidPunctuation, userInputString))
                {
                    //if we find that the user input contains numbers, is an email address, or is otherwise invalid
                    //let's repeat their input, clear the user input field, and try again
                    Console.WriteLine(userInputString);
                    userInputString = "";
                    continue;
                }
                #endregion
                //If we get to this point, let's translate the user's input into Pig Latin
                //let's try the simplest translation first
                Console.WriteLine(PigLatinTranslator(userInputString));

                #region Learning words, checking user's input string against words we know
                //Let's also add each word to a dictionary we keep building on as we learn it,
                //so the program is smart enough to know when the user is entering a string of nonsense
                //Let's store this with StreamWriter and StreamReader at first, then serialize/deserialize data later
                #endregion

                //ask the user if they want to translate another word
                userInputString = "";
                userAnswer      = UserInput.GetYesOrNoAnswer("Do you wish to translate again? ");
                switch (userAnswer)
                {
                case YesNoAnswer.Yes: continue;

                case YesNoAnswer.No: return;

                default: continue;
                }
            }
        }
コード例 #10
0
        public void Execute()
        {
            YesNoQuestion yesNoQuestion = new YesNoQuestion("Do you want to play previous game?");
            YesNoAnswer   answer        = yesNoQuestion.ReadAnswer();

            if (answer.Equals(YesNoAnswer.Yes))
            {
                _loadGameList();
            }
        }
コード例 #11
0
 public ActionResult Edit([Bind(Include = "YesNoAnswerID,Name")] YesNoAnswer yesNoAnswer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(yesNoAnswer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(yesNoAnswer));
 }
コード例 #12
0
        public ActionResult Create([Bind(Include = "YesNoAnswerID,Name")] YesNoAnswer yesNoAnswer)
        {
            if (ModelState.IsValid)
            {
                db.YesNoAnswers.Add(yesNoAnswer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(yesNoAnswer));
        }
コード例 #13
0
        public void Voted(PollDTO polDTO, User user)
        {
            YesNoAnswer answer = new YesNoAnswer();

            answer = polDTO.YesNoAnswer;
            answer.YesNoQuestionId = polDTO.YesNoQuestion.Id;
            yesNoAnswerDal.AddYesNoAnswer(answer);
            UserPoll userPoll = new UserPoll();

            userPoll.PollId = polDTO.Poll.Id;
            userPoll.UserId = user.Id;
            userSurveysDal.Add(userPoll);
        }
コード例 #14
0
        // GET: YesNoAnswers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            YesNoAnswer yesNoAnswer = db.YesNoAnswers.Find(id);

            if (yesNoAnswer == null)
            {
                return(HttpNotFound());
            }
            return(View(yesNoAnswer));
        }
コード例 #15
0
        /// <summary>
        /// Displays the question to the user and waits for the answer.
        /// </summary>
        protected override void DoDisplayContent(ControlDisplay display)
        {
            if (QuestionText != null)
            {
                DisplayQuestion();
            }

            DisplayPossibleAnswersList();

            if (SpaceAfterQuestion > 0)
            {
                DisplaySpaceAfterQuestion();
            }

            Answer = ReadAnswerInternal();
        }
コード例 #16
0
        public static void DeletePerson(List <Person> masterList)
        {
            MenuHandling.PrintMenuOptions(masterList.ToArray(), menuMode: true, messagePrompt: "Here are our peeps:");
            var userSelection = UserInput.SelectMenuOption(masterList.Count);

            YesNoAnswer yesNo = UserInput.GetYesOrNoAnswer("Are you sure? (y/n or yes/no): ");

            switch (yesNo)
            {
            case YesNoAnswer.Yes: masterList.RemoveAt((int)userSelection - 1); break;

            case YesNoAnswer.No: break;

            default: break;
            }
        }
コード例 #17
0
        static void Main(string[] args)
        {
            double maxArrayValue = 0.00;

            while (true)
            {
                //Console.WriteLine("Please enter the number of values we'll be entering: ");

                while (!int.TryParse(userResponse, out arraySize) || arraySize < 1)
                {
                    UserInput.PromptUntilValidEntry("Please enter the number of values we'll be entering (number needs to be greater than zero): ", ref userResponse, InformationType.Numeric);
                }
                userValues   = new double[arraySize];
                userResponse = "";

                for (int i = 0; i < userValues.Length; i++)
                {
                    Console.Write("Please enter a number: ");
                    while (!double.TryParse(Console.ReadLine(), out userValues[i]))
                    {
                        Console.Write("Invalid entry. Please enter a number: ");
                    }
                }

                foreach (double k in userValues)
                {
                    if (k > maxArrayValue)
                    {
                        maxArrayValue = k;
                    }
                }
                Console.WriteLine("Maximum value of the numbers you entered is: \n{0} . ", maxArrayValue);

                maxArrayValue = 0;
                userResponse  = "";
                userValues    = null;

                YesNoAnswer yesNoAnswer = UserInput.GetYesOrNoAnswer("Would you like to enter another set of numbers? ");

                switch (yesNoAnswer)
                {
                case YesNoAnswer.Yes: continue;

                case YesNoAnswer.No: return;
                }
            }
        }
コード例 #18
0
ファイル: ExitCommand.cs プロジェクト: vinhins/ConsoleTools
        public void Execute(CliCommand cliCommand)
        {
            YesNoQuestion yesNoQuestion = new YesNoQuestion("Are you sure?")
            {
                DefaultAnswer = YesNoAnswer.Yes
            };

            YesNoAnswer answer = yesNoQuestion.ReadAnswer();

            if (answer == YesNoAnswer.Yes)
            {
                Program.RequestClose();
            }
            else
            {
                CustomConsole.WriteLine();
            }
        }
コード例 #19
0
        static StudentInfo AddStudent()
        {
            YesNoAnswer userAnswer = YesNoAnswer.AnswerNotGiven;
            StudentInfo tmpStudent;
            string      newStudentName       = "";
            string      newStudentData_Label = "";
            string      newStudentData_Field = "";

            //have user enter student's name
            Console.Write("Please enter new student's name: ");
            while (!Validation.ValidateInfo(InformationType.Name, newStudentName))
            {
                newStudentName = Console.ReadLine();
                if (!Validation.ValidateInfo(InformationType.Name, newStudentName))
                {
                    Console.Write("I didnt recognize that as a valid name. Please enter a valid name (1-30 characters, no spaces): ");
                }
            }
            tmpStudent = new StudentInfo(newStudentName);

            //prompt user to enter as much information as they have available about a student, and answer with "no" when they have no more info to add
            //(don't allow a user to enter an information type without an information value, and don't allow blank fields)
            while (userAnswer != YesNoAnswer.No)
            {
                userAnswer = UserInput.GetYesOrNoAnswer($"Would you like to enter more information about {tmpStudent.Name}? (y/n) ");
                switch (userAnswer)
                {
                case YesNoAnswer.Yes:
                {
                    newStudentData_Label = "";
                    newStudentData_Field = "";

                    tmpStudent.AddField(newStudentData_Label, newStudentData_Field);
                    break;
                }

                case YesNoAnswer.No: break;
                }
            }
            return(tmpStudent);
        }
コード例 #20
0
        public static void AddPerson(List <Person> masterList)
        {
            string userEntry   = "";
            uint   ageEntry    = 0;
            double salaryEntry = 0.00;

            YesNoAnswer isTeamMember = UserInput.GetYesOrNoAnswer("Is this new person a Team Member? (y/n or yes/no. If so, we'll ask you for salary information): ");

            Person tmp = isTeamMember == YesNoAnswer.Yes ? new TeamMember() : new Person();

            tmp.FirstName = UserInput.PromptUntilValidEntry("Please enter new person's first name (first letter capitalized, 1-30 alphabetic characters): ", InformationType.Name);
            tmp.LastName  = UserInput.PromptUntilValidEntry("Please enter new person's last name (1-30 alphabetic characters): ", InformationType.LastName);

            while (!uint.TryParse(userEntry, out ageEntry) || ageEntry < 0)
            {
                userEntry = UserInput.PromptUntilValidEntry("Please enter new person's age: ", InformationType.Numeric);
            }
            tmp.Age = ageEntry;
            if (!tmp.CheckIfAdult())
            {
                Console.WriteLine("New people added to this list must be 18 or older (apparently we're having some kind of party.)");
                return;
            }
            else
            {
                //if we know the person is an adult and will be added to our list, then let's proceed
                tmp.EmailAddress = UserInput.PromptUntilValidEntry("Please enter new person's email address: ", InformationType.EmailAddress);

                if (tmp is TeamMember)
                {
                    userEntry = "";
                    while (!double.TryParse(userEntry, out salaryEntry) || salaryEntry < 0)
                    {
                        userEntry = UserInput.PromptUntilValidEntry("Please enter new person's salary: $", InformationType.Numeric);
                    }
                    (tmp as TeamMember).Salary = salaryEntry;
                }
                masterList.Add(tmp);
            }
        }
コード例 #21
0
        /// <summary>
        /// This function prompts the user to type "y", "yes", "n", or "no" to provide a yes-or-no answer. Function stays in a loop until
        /// user enters something we recognize as a yes or no answer.
        /// </summary>
        /// <returns>A yes-or-no answer enum set to Yes, No, or Answer Not Given. </returns>
        public static YesNoAnswer GetYesOrNoAnswer(string questionPrompt)
        {
            YesNoAnswer tmp          = YesNoAnswer.AnswerNotGiven;
            string      userResponse = "";

            while (userResponse != "y" && userResponse != "yes" &&
                   userResponse != "n" && userResponse != "no")
            {
                Console.Write(questionPrompt);
                userResponse = Console.ReadLine().Trim().ToLower();
            }
            switch (userResponse)
            {
            case "y":
            case "yes": tmp = YesNoAnswer.Yes; break;

            case "n":
            case "no":  tmp = YesNoAnswer.No; break;

            default: tmp = YesNoAnswer.AnswerNotGiven; break;
            }
            return(tmp);
        }
コード例 #22
0
        public static void DeletePerson(List <Person> masterList)
        {
            MenuHandling.PrintMenuOptions(masterList.ToArray(), menuMode: true, messagePrompt: $"Here's a list of our peeps. Press 1-{masterList.Count} to delete a person from the list, or {masterList.Count + 1} to go back:");
            Console.WriteLine($"{masterList.Count + 1}.) Go back");

            //let's allow for the possibility that this method will return one more than the length of the list, just so we have a "go back" option
            var userSelection = UserInput.SelectMenuOption(masterList.Count + 1);

            if (userSelection == masterList.Count + 1)
            {
                return;
            }

            YesNoAnswer yesNo = UserInput.GetYesOrNoAnswer("Are you sure? (y/n or yes/no): ");

            switch (yesNo)
            {
            case YesNoAnswer.Yes: masterList.RemoveAt((int)userSelection - 1); break;

            case YesNoAnswer.No: break;

            default: break;
            }
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: jpzimmerman/Buy_A_Vowel
        static void Main(string[] args)
        {
            YesNoAnswer userAnswer = YesNoAnswer.AnswerNotGiven;

            Console.Write("***********************************************************\n" +
                          "*            Dev.Build(2.0) - Count the Vowels            *\n" +
                          "***********************************************************\n\n");
            while (true)
            {
                //Have user enter string
                Console.Write("Please enter some text, and I'll count the vowels: ");
                string userString = Console.ReadLine();

                //sent string to CountVowels to determine number of vowels present
                CountVowels(userString);

                //display number of vowels present
                DisplayVowels();

                //reset vowel counters in our Dictionary
                inputVowels['a'] = 0;
                inputVowels['e'] = 0;
                inputVowels['i'] = 0;
                inputVowels['o'] = 0;
                inputVowels['u'] = 0;

                //ask user if they would like to continue
                userAnswer = UserInput.GetYesOrNoAnswer("Would you like to enter another string? ");
                switch (userAnswer)
                {
                case YesNoAnswer.Yes: userAnswer = YesNoAnswer.AnswerNotGiven; continue;

                case YesNoAnswer.No: userAnswer = YesNoAnswer.AnswerNotGiven; return;
                }
            }
        }
コード例 #24
0
        static void Main(string[] args)
        {
            YesNoAnswer userAnswer    = YesNoAnswer.AnswerNotGiven;
            uint        userSelection = 0;
            string      userEntry     = "";
            StudentInfo tmpStudent    = new StudentInfo();

            StudentInfo.BuildInitialStudentList(ref newStudents);

            while (true)
            {
ProgramStart:
                DisplayStudentList();
                //since we may come back to the top of the loop, let's make sure this is set to false each time we get here
                validData = false;
                while (!validData)
                {
                    tmpStudent = SelectStudent(out userSelection);
                    if (userSelection == newStudents.Count + 1)
                    {
                        newStudents.Add(AddStudent());
                        goto ProgramStart;
                    }
                    if (userSelection == newStudents.Count + 2)
                    {
                        AddFieldForAllStudents();
                        goto ProgramStart;
                    }
                }

                tmpStudent = newStudents[(int)userSelection - 1];
                Console.WriteLine($"Student {userSelection} is {tmpStudent.Name}");

                validData = false;
                while (!validData)
                {
                    Console.WriteLine($"What would you like to know about {tmpStudent.Name}? ");
                    Console.Write("Valid options for this student are: ");
                    foreach (string str in tmpStudent.Info.Keys)
                    {
                        Console.Write(str + " | ");
                    }
                    while (!validData)
                    {
                        userEntry = Console.ReadLine().Trim();
                        validData = FetchAndPrintData(tmpStudent, userEntry.Trim().ToLower());
                    }

                    userAnswer = UserInput.GetYesOrNoAnswer("Do you want information for another student? (y/n) ");
                    switch (userAnswer)
                    {
                    case YesNoAnswer.Yes:
                    {
                        //Let's do some cleanup before taking it from the top, making sure everything is reset before the start of the loop
                        userAnswer    = YesNoAnswer.AnswerNotGiven;
                        userEntry     = "";
                        userSelection = 0;
                        validData     = true;
                        Console.WriteLine("\n");
                        tmpStudent = null;
                        goto ProgramStart;
                    }

                    case YesNoAnswer.No: return;
                    }
                }
            }
        }
コード例 #25
0
 public IActionResult Edit(YesNoAnswer yesNoAnswer)
 {
     return(View(yesNoAnswer));
 }
コード例 #26
0
 public void AddYesNoAnswer(YesNoAnswer answer)
 {
     yesNoAnswerDal.AddYesNoAnswer(answer);
 }
コード例 #27
0
 public void AddYesNoAnswer(YesNoAnswer answer)
 {
     dbContext.Add(answer);
     dbContext.SaveChanges();
 }