Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# Programming, need assistance with a method in Visual Basic. I have written th

ID: 3600923 • Letter: C

Question

C# Programming, need assistance with a method in Visual Basic. I have written the code but it's not correct.

Error checking:

- The program should only accept 'm', 'o' and 'p' as the type of wood. If the user enters an invalid value, an error message should be displayed and the user should be prompted to enter a valid entry.   The error checking should occur in the method that accepts the type of wood.

private string GetWood(string wood)
{
//assigning value to type of wood
string ch;
wood.ToLower();
if (wood == "Mahogany")
ch = "m";
else if (wood == "Oak")
ch = "o";
else if (wood == "Pine")
ch = "p";
else
ch = "null";
{
MessageBox.Show("Wood type is invalid, please enter the correct type of wood.");
bContinue = false;
}
return ch;
}

Explanation / Answer

Solution=====================

As per the question, we are expecting "wood" value to be either 'm', 'o' and 'p' , so need to check for these, also "else" section ch assignmnet had to be within the braces.

private string GetWood(string wood)
        {
            //assigning value to type of wood
            string ch;
            wood.ToLower();
            if (wood == "m")
                ch = "Mahogany";
            else if (wood == "o")
                ch = "Oak";
            else if (wood == "p")
                ch = "Pine";
            else
            {
                ch = "null";
                MessageBox.Show("Wood type is invalid, please enter the correct type of wood.");
            }
            return ch;
        }

Let me know if any doubts...