Hello, I’m working on this task:
Task with high complexity! It is ok to skip
Noname’s functional module consists of 4 functions: FromAToF, FromGToL, FromMToR, and FromSToZ, but Noname doesn’t know when to call which one. You need to write a program - think of it as a dispatcher - that routes an entered command to the correct function. You should read input commands from the console and if the command begins with a letter in the English alphabet that is located between “a” and “f”, such as “fix” or “Comment,” you should call function FromAToF with the command as a parameter. If the first letter of the command is between “g” and “l”, you should call FromGToL, again with the command as a parameter. Similarly, if the first letter is between “m” and “r”, call FromMToR with the command as a parameter, and in all other cases, call FromSToZ with the command as a parameter. For this program, commands are guaranteed to start with a letter. But pay attention: it can be either an uppercase or lowercase letter; for example, “fix” or “Fix”. Your program should therefore be case-insensitive. The program should listen to the input commands, and when one is given, run the method corresponding to that command. When the user types “exit”, the program should exit. For example:
>collapse
FromAToF executes collapse.
>Globalize
FromGToL executes Globalize.
>optimize
FromMToR executes optimize.
>Wrap
FromSToZ executes Wrap.
>exit
Here is my code:
namespace Methods
{
class FunctionalModule
{
static void Main(string[] args)
{
bool listeningToCommands = true;
while (listeningToCommands) {
string command = Console.ReadLine();
char firstLetter = char.Parse(command.Substring(0, 1));
int ascii = Convert.ToByte(firstLetter);
Console.WriteLine(command);
if (command == "exit") {
listeningToCommands = false;
} else if ((ascii >= 65 && ascii <= 70) || (ascii >= 97 && ascii <= 102)) {
FromAToF(command);
} else if ((ascii >= 71 && ascii <= 76) || (ascii >= 103 && ascii <= 108)) {
FromGToL(command);
} else if ((ascii >= 77 && ascii <= 82) || (ascii >= 109 && ascii <= 114)) {
FromMToR(command);
} else if ((ascii >= 83 && ascii <= 90) || (ascii >= 115 && ascii <= 122)) {
FromSToZ(command);
}
}
}
static void FromAToF(string command)
{
Console.WriteLine($"FromAToF executes {command}.");
}
static void FromGToL(string command)
{
Console.WriteLine($"FromGToL executes {command}.");
}
static void FromMToR(string command)
{
Console.WriteLine($"FromMToR executes {command}.");
}
static void FromSToZ(string command)
{
Console.WriteLine($"FromSToZ executes {command}.");
}
}
}
Can anyone please help me to pass the testing of this code?