Fill This Form To Receive Instant Help
Homework answers / question archive / This assignment will simulate a guessing game
This assignment will simulate a guessing game. Imagine two people are bored in the car driving on a road trip. Create a program that uses the following steps.
First person thinks of a number. Ask the user to input a number.
First person then asks the second person the guess the number - ask the user to guess the number.
If the number matches, print the output X is correct! and exit the program
If the number doesn't match, print Wrong on a line by istelf, then go back to step 2 and continue asking for the number until the correct answer is given.
using System; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 namespace Test { [AttributeUsage (AttributeTargets. All)] public class PointsAttribute : Attribute { public pointsAttribute(int points) { Points = points; } public int Points { get; } } } => this.Output.Split(Environment. NewLine, StringSplitOptions. RemoveEmptyEntries); 34 35 36 [TestInitialize] O references public void InitializeTest() { // Redirect the console output this.consoleOutput = new StringWriter(); Console.SetOut(this.consoleOutput); 37 38 39 40 41 42 43 44 45 46 47 // Configure the console input this.SetUpInput (string. Empty); } 48 49 50 51 52 53 [TestCleanup] O references public void CleanupTest() { this.consoleOutput.Dispose(); this.consoleInput.Dispose(); } 2 references protected void SetupInput(string input) { this.consoleInput?.Dispose(); 54 55 56 57 58 59 60 61 this.consoleInput = new StringReader(input); Console.SetIn(this.consoleInput); } 62 63 64 65 4 references protected void SetUpInput (params object[] inputs) { var input string. Join (Environment. Newline, inputs); this.SetUpInput(input); = 66 67 68 69 { 1 2 3 4 using System; using System.IO; using Microsoft.VisualStudio. TestTools.UnitTesting; 5 6 7 8 namespace Test { 1 reference public class TestBase { private StringWriter consoleOutput; private StringReader consoleInput; private string output; 9 10 11 12 13 14 15 /// /// Gets all of the text printed to the console /// 1 reference public string Output { Bet { 16 17 18 19 20 21 2- 22 22 23 24 27 25 26 27 28 29 30 31 32 if (output == null) { this.consoleOutput.Flush(); output = this.consoleOutput. GetStringBuilder().ToString(); } return output; } /// /// Gets the test printed to the console with a separate array element per line /// 4 references public string[] OutputByLine 33 using System; using System.Linq; using ITS$131; using Microsoft.VisualStudio. TestTools.UnitTesting; 1 2 3 4 5 6 7 8 - 9 10 11 12 13 namespace Test { [Testclass] O references public class UnitTest : TestBase { [TestMethod] [Points (25)] [Timeout(2000)] O references public void ListsWrongTwice) = this.SetUpInput(19,8,15,19); Program.Main(null); 14 15 16 17 18 19 20 21 22 23 24 25 Assert. Are Equal(2, this.OutputByLine.count(x => x.Contains("wrong", String Comparison.OrdinalIgnorecase)); } [TestMethod] [Points (25)] [Timeout(2000)] O references public void ListsFinalCorrectLine() { this.SetUpInput(19,8,15,19); 26 27 28 Program.Main(null); 29 30 31 32 33 Assert.IsTrue(this.OutputByLine.Last().Contains("19 is correct", Stringcomparison.OrdinalIgnoreCase)); } 34 35 36 37 [TestMethod] [Points(25)] [Timeout(2000)] O references public void GuessCorrectFirstTryNoWrongs() { this.SetUpInput(13,13); 38 39 40 41 42 43 44 45 46 47 Program. Main(null); Assert. AreEqual(@, this.OutputByLine.count(x => x.Contains("wrong", StringComparison.OrdinalIgnoreCase)); } 48 49 [TestMethod] [Points (25)] [Timeout(2000)] O references public void GuessCorrectFirstTryCorrectLastLine() { this.SetUpInput(13, 13); 50 51 52 53 54 55 56 57 Program.Main(null); Assert.IsTrue(this.OutputByLine.Last().Contains("13 is correct", String Comparison.OrdinalIgnoreCase)); } 58 59 60