Question: SIT 7 7 1 Object - Oriented Development Pass Task 3 . 1 : Name Tester Focus Make the most of this task by focusing
SIT ObjectOriented Development
Pass Task : 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 errorfree 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 nametesting 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
between and letting them know if their guess was smaller or larger than their goal.
The material in Course Week 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 Programcs
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
Create a new project folder named
settings in this folder.
Open the projectfolder in Visual Studio Code.
Open the Program.cs file.
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 and
will map to the integer value
will map to
Here is a start for this enum.
Console.WriteLine
Console.ReadLine
NameTester dotnet
MenuOption TestName
GuessThatNumber
GuessThatNumber Quit
ReadUserOption
option
Console.WriteLine
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
Start the method by declaring an
value of the option the user selects.
integer variable. We will use this to store the
Use to output a menu showing the three options. will run Test
Name, will play Guess That Number, and will Quit". Add a header and use or to put
borders around things to make them look a little nicer.
Start a do while loop...
Use
:
to show the user a prompt, something like "Choose an option
Use and to read in the user's selection
and convert it to an integer. Store this in a variable for later use.
End the do while loop, having the above code loop while the value read in by the user is
less than or larger than
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.ToInt
MenuOption
TestName
MenuOption
MenuOption.GuessThatNumber
MenuOption.Quit
Main
return MenuOptionoption ;
public static void Main
MenuOption userSelection;
userSelection ReadUserOption;
Console.WriteLineuserSelection;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
