Hello, I’m working on this task:
Commander’s communication module was still partially write-protected. Noname and I have found a way to insert a new class and to change 10 symbols in the Main method. Methods ReceiveMessage and SendMessage were 100% protected and we were not able to make any changes.
Create your own public implementation of ICommunicationModule named CommunicationToTeo that is an exact copy of CommunicationToWonderland with one exception: instead of the string “Opening communication channel to Wonderland” it should say “Opening communication channel to Teo”. Then, replace the communication module that is used in the Main method with the newly created CommunicationToTeo.
Here is my code:
namespace Polymorphism
{
public interface ICommunicationModule
{
void Send(string message);
string Receive();
}
public class CommunicationToWonderland : ICommunicationModule
{
public void Send(string message)
{
Console.WriteLine("Opening communication channel to Wonderland");
Console.WriteLine($"Sending message: {message}");
}
public string Receive()
{
Console.WriteLine("Opening communication channel to Wonderland");
var message = Console.ReadLine();
Console.WriteLine($"Received message: {message}");
return message;
}
}
public class CommunicationToTeo : ICommunicationModule
{
public void Send(string message)
{
Console.WriteLine("Opening communication channel to Teo");
Console.WriteLine($"Sending message: {message}");
}
public string Receive()
{
Console.WriteLine("Opening communication channel to Wonderland");
var message = Console.ReadLine();
Console.WriteLine($"Received message: {message}");
return message;
}
}
public class CommandersCommunicationSystem
{
public static void Main()
{
var communicationToWonderland = new CommunicationToTeo(); // Change this line
var message = Console.ReadLine();
SendMessage(communicationToWonderland, message);
var receivedMessage = ReceiveMessage(communicationToWonderland);
}
static string ReceiveMessage(ICommunicationModule communicationModule)
{
return communicationModule.Receive();
}
static void SendMessage(ICommunicationModule communicationModule, string message)
{
communicationModule.Send(message);
}
}
}
Can anyone please help me to solve it?