Never send a human to do a machine's job

    Hello gentlemen.
    As a newbie to C # and .NET, I asked yesterday at stackoverflow ( http://stackoverflow.com/questions/2192808/simple-but-interesting-task-for-c-newbie ) for newbie test suggestions. As a result, I received a number of answers, interesting and not very. But among them, one stood out favorably, with a proposal to solve the programmer quiz.

    The goal of the puzzle is to use the available classes (code 1) to display the phrase that I put in the topic of this publication. For those who want to read the post in the original, I gave a link to the question itself above, the search answer there is marked as accepted. For everyone else, the task itself is:

    1. using System;
    2.  
    3. public interface IWord {
    4.   void Print();
    5. }
    6.  
    7. public interface IWord2 : IWord {
    8.   new void Print();
    9. }
    10.  
    11. public abstract class Base {
    12.   protected static string msg = "send ";
    13.  
    14.   public Base() {
    15.      Console.Write(this.GetString());
    16.   }
    17.  
    18.   static Base() {
    19.      Console.Write("Never ");
    20.   }
    21.  
    22.   public virtual void Print() {
    23.      Console.Write("to ");
    24.   }
    25.  
    26.   protected virtual string GetString() {
    27.      return "llama ";
    28.   }
    29. }
    30.  
    31. public class Derived : Base, IWord {
    32.  
    33.   static Derived() {
    34.      Console.Write(Derived.msg);
    35.   }
    36.  
    37.   public new virtual void Print() {
    38.      Console.Write("do ");
    39.   }
    40.  
    41.   protected override string GetString() {
    42.      return "a ";
    43.   }
    44. }
    45.  
    46. public sealed class MoreDerived : Derived, IWord {
    47.   public override void Print() {
    48.      Console.Write("mach");
    49.   }
    50.  
    51.   void IWord.Print() {
    52.      Console.Write("a ");
    53.   }
    54.  
    55.   protected override string GetString() {
    56.      return "do ";
    57.   }
    58. }
    59.  
    60. public sealed class MoreDerived2 : Derived, IWord2 {
    61.  
    62.   static MoreDerived2() {
    63.      Console.Write("ine");
    64.   }
    65.  
    66.   public new void Print() {
    67.      Console.Write("job. ");
    68.   }
    69.  
    70.   void IWord2.Print() {
    71.      Console.Write("job.");
    72.   }
    73.  
    74.   protected override string GetString() {
    75.      return "'s ";
    76.   }
    77. }
    78.  
    79. public abstract class Unfinished : Base {
    80.   protected new void Print() {
    81.      Console.Write("camel ");
    82.   }
    83.  
    84.   protected override string GetString() {
    85.      return "human ";
    86.   }
    87. }
    88.  
    89. public class Finished: Unfinished {
    90. }
    * This source code was highlighted with Source Code Highlighter.


    The author of this answer proposes to implement the code itself inside
    1. using System;
    2.  
    3. public class AgentSmith {
    4.   //Never send a human to do a machine's job.
    5.   public static void Main()
    6.   {
    7.      //put your code here
    8.  
    9.      Console.ReadLine();
    10.   }
    11. }
    * This source code was highlighted with Source Code Highlighter.


    PS: I haven’t decided yet (but there are certain thoughts, of course), therefore, more experienced comrades, do not leave spoilers in the comments :-)

    Thank you all and good luck with the solution :-)

    UPD 1: fixed according to the first comment, however, I am not entirely sure that the conditions of the task prohibit the creation of new classes + inheritance. and I’m not sure that the problem can be solved without this. naturally I could be wrong.

    Also popular now: