Question: SIT 7 7 1 Object - Oriented Development Pass Task 3 . 1 : Name Tester Focus Make the most of this task by focusing

SIT771 Object-Oriented Development
Pass Task 3.1: Name Tester
Focus
Make the most of this task by focusing on the following:
Syntax:
Focus on learning the basic C# syntax and structure of creating enumerations and using control
flow statements.
Concept:
Focus on the idea of control flow statements, what are the different types, and how and when they
are to be used. Alongside this, explore the concepts of Error Handling and enumerations.
Process:
Consolidate your understanding of how to build and run programs error-free with enumerations
and control flow statements to perform different series of actions as per the desired output.
Overview
In this task, you will create a simple name-testing program in order to explore the different kinds of
control flow statements. The program will have a small menu to allow the user to choose between
several options: testing a name, guessing that number, and quitting. The name tester will read in the
user's name and output a custom message. Guess that number will ask the user to guess a number
between1 and 100, letting them know if their guess was smaller or larger than their goal.
The material in Course 2, Week 1 will help you with this task.
This task has lots of details, but by the end, you will have worked through the use of each kind of
control flow structure. We have tried to add guidance so that you will see how to put this program
together.
Submission Details
Submit the following files to OnTrack.
The Program code (Program.cs)
A screenshot of the running program
You want to focus on the different control flow statements and think about how they work when you
run your program. The program will be built in multiple steps so that you can see each part working as
you go.
Instructions
We are going to build this program over a number of steps. This is always a good idea, and in this case
it will let us focus on the different control flow statements one at a time.
The following UML class diagram shows the class and enumeration that we will build in this task.
Quit
TestName
public enum MenuOption
{
TestName,
//... continue here
}
Figure: UML class diagram for the name tester program
Reading a Menu options
To get started lets show a menu to the user and read the option they want to perform. This program will
use the Terminal to interact with the user, so we can use
to show and read values from the user.
and
1. Create a new project folder named
settings in this folder.
2. Open the project/folder in Visual Studio Code.
3. Open the Program.cs file.
4. Create a new enumeration called
, and use
, with the options
to create and restore the
,
, and .
Place this outside of the Program class, either before or after the Program class code. Keep the
options in that order, this way we know that
will map to 1, and
will map to the integer value 0,
will map to 2.
Here is a start for this enum.
Console.WriteLine
Console.ReadLine
NameTester dotnet
MenuOption TestName
GuessThatNumber
GuessThatNumber Quit
ReadUserOption
option
Console.WriteLine
5. Create a new
class.
method that returns a inside the Program
This method will show the menu to the user and read in their selection.
The method should perform the following steps. These are expressed here
as pseudocode (which is code like text, often used to express how an algorithm should work).
Remember to add the
class itself.
keyword to this method, as we will run it directly on the
1. Start the method by declaring an
value of the option the user selects.
integer variable. We will use this to store the
2. Use to output a menu showing the three options. "1 will run Test
Name, 2 will play Guess That Number, and 3 will Quit". Add a header and use "*" or "-" to put
borders around things to make them look a little nicer.
3. Start a do ... while loop...
1. Use
[1-3]: "
to show the user a prompt, something like "Choose an option
2. Use and to read in the user's selection
and convert it to an integer. Store this in a variable for later use.
4. End the do ... while loop, having the above code loop while the value read in by the user is
less than 1 or larger than 3.
In this way we can force the user to choose a valid option. We ask them to enter the value,
then loop while it is not a valid option.
private static MenuOption ReadUserOption()
{
// steps go here...
}
ReadUserOption MenuOption
static
Program
Console.Write
Console.ReadLine Convert.ToInt32
MenuOption
TestName
(MenuOption)
0
MenuOption.GuessThatNumber
MenuOption.Quit
Main
return (MenuOption)(option -1);
public static void Main()
{
MenuOption userSelection;
userSelection = ReadUserOption();
Console.WriteLine(userSelection);
}
5. Lastly, we can return the matching . We can make use of our understanding
of enumerations, and the fact that each enumeration value is actually an integer. If you
named the variable option, then the following code will return the matching MenuOptio

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!