C# I need to Write a program named InputMethodDemo2 that eliminates the repetitive code in the InputMethod() in the InputMethodDemo program in Figure 8-5. Rewrite the program so the InputMethod() contains only two statements: one = DataEntry("first"); two = DataEntry("second"); (Note: The program in Figure 8-5 is provided as starter code.) Figure 8-5:(picture) my errors are  Method DataEntry is defined to eliminate repetitive code   0 out of 1 checks passed. Review the results below for more details. Unit Test Incomplete Method DataEntry prompts the user to enter an integer and returns the integer Build Status Build Succeeded Test Output NUnit Console Runner 3.10.0 (.NET 2.0) Copyright (c) 2019 Charlie Poole, Rob Prouse Saturday, 04 February 2023 19:37:31   Runtime Environment   OS Version: Linux 5.0.0.27 CLR Version: 4.0.30319.42000 Test Files NtTestf1b2147f.dll Errors, Failures and Warnings 1) Failed : DataEntryMethodTest.DataEntryTest Expected string length 19 but was 24. Strings differ at index 8. Expected: "Enter third integer" But was: "Enter the third integer:" -------------------^ at DataEntryMethodTest.DataEntryTest () [0x00000] in <6cf807bbba6c4dd284af123222270fc6>:0 Run Settings DisposeRunners: True WorkDirectory: /root/sandboxbf049929 ImageRuntimeVersion: 4.0.30319 ImageRequiresX86: False ImageRequiresDefaultAppDomainAssemblyResolver: False NumberOfTestWorkers: 4 Test Run Summary Overall result: Failed Test Count: 1, Passed: 0, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0 Failed Tests - Failures: 1, Errors: 0, Invalid: 0 Start time: 2023-02-04 19:37:32Z End time: 2023-02-04 19:37:33Z Duration: 1.157 seconds   [TestFixture] public class DataEntryMethodTest { [Test] public void DataEntryTest() { string consoleInput = "97"; int returnedValue; string expectedString = "Enter third integer"; using (var inputs = new StringReader(consoleInput)) { Console.SetIn(inputs); using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); returnedValue = InputMethodDemo2.DataEntry("third"); Assert.AreEqual(expectedString, sw.ToString().Trim()); Assert.AreEqual(97, returnedValue); } } } } my code   using System; using static System.Console; class InputMethodDemo2 {     static void Main()     {         int first, second;         InputMethod(out first, out second);         WriteLine("After calling InputMethod, the first number is: {0}", first);         WriteLine("And the second number is: {0}", second);     }      private static void InputMethod(out int one, out int two)     {         one = DataEntry("first");         two = DataEntry("second");     }          public static int DataEntry(string prompt)     {         Write("Enter the {0} integer: ", prompt);         string input = ReadLine();         return Convert.ToInt32(input);     } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 C#

I need to Write a program named InputMethodDemo2 that eliminates the repetitive code in the InputMethod() in the InputMethodDemo program in Figure 8-5.

Rewrite the program so the InputMethod() contains only two statements:

one = DataEntry("first");
two = DataEntry("second");

(Note: The program in Figure 8-5 is provided as starter code.)

Figure 8-5:(picture)

my errors are 

Method DataEntry is defined to eliminate repetitive code

 
0 out of 1 checks passed. Review the results below for more details.

Unit Test Incomplete

Method DataEntry prompts the user to enter an integer and returns the integer

Build Status
Build Succeeded
Test Output
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Saturday, 04 February 2023 19:37:31
 
Runtime Environment
 
OS Version: Linux 5.0.0.27
CLR Version: 4.0.30319.42000
Test Files
NtTestf1b2147f.dll
Errors, Failures and Warnings
1) Failed : DataEntryMethodTest.DataEntryTest
Expected string length 19 but was 24. Strings differ at index 8.
Expected: "Enter third integer"
But was: "Enter the third integer:" -------------------^
at DataEntryMethodTest.DataEntryTest () [0x00000] in <6cf807bbba6c4dd284af123222270fc6>:0
Run Settings
DisposeRunners: True
WorkDirectory: /root/sandboxbf049929
ImageRuntimeVersion: 4.0.30319
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Test Run Summary
Overall result: Failed
Test Count: 1, Passed: 0, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0
Failed Tests - Failures: 1, Errors: 0, Invalid: 0
Start time: 2023-02-04 19:37:32Z
End time: 2023-02-04 19:37:33Z
Duration: 1.157 seconds
 
[TestFixture]
public class DataEntryMethodTest
{
[Test]
public void DataEntryTest()
{
string consoleInput = "97";
int returnedValue;
string expectedString = "Enter third integer";
using (var inputs = new StringReader(consoleInput))
{
Console.SetIn(inputs);
using (StringWriter sw = new StringWriter())
{
Console.SetOut(sw);
returnedValue = InputMethodDemo2.DataEntry("third");
Assert.AreEqual(expectedString, sw.ToString().Trim());
Assert.AreEqual(97, returnedValue);
}
}
}
}

my code
 

using System;
using static System.Console;

class InputMethodDemo2
{
    static void Main()
    {
        int first, second;
        InputMethod(out first, out second);
        WriteLine("After calling InputMethod, the first number is: {0}", first);
        WriteLine("And the second number is: {0}", second);
    } 
    private static void InputMethod(out int one, out int two)
    {
        one = DataEntry("first");
        two = DataEntry("second");
    }
    
    public static int DataEntry(string prompt)
    {
        Write("Enter the {0} integer: ", prompt);
        string input = ReadLine();
        return Convert.ToInt32(input);
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY