Please help me with the task: String rules

Hello, I’m working on this task:

In the Main method, create two string rules of types NoDoubleSpaces and IsShort. Call the method DoesTheRuleApply two times, once for each rule. Assign the result to the corresponding variables hasNoDoubleSpaces and isShort. You also need to call the method AppliesToString inside the method DoesTheRuleApply. Set the type IStringRule to the method’s parameter rule. Don’t change any function or parameter names.

Here is my code:


namespace Polymorphism
{
   public interface IStringRule
   {
       bool AppliesToString(string input);
   }

   public class NoDoubleSpaces : IStringRule
   {
       public bool AppliesToString(string input)
       {
           if (input == null)
               return false;

           for (int i = 0; i < input.Length - 1; i++)
           {
               if (input[i] == ' ' && input[i + 1] == ' ')
                   return false;
           }

           return true;
       }
   }

   public class IsShort : IStringRule
   {
       public bool AppliesToString(string input)
       {
           return input != null && input.Length < 10;
       }
   }

   public class StringRules
   {
       public static void Main()
       {
           var input = Console.ReadLine();
           var hasNoDoubleSpaces = false;
           var isShort = false;

           // Write your code here
           NoDoubleSpaces rule1 = new NoDoubleSpaces();
           IsShort rule2 = new IsShort();

           DoesTheRuleApply(rule1, input);
           DoesTheRuleApply(rule2, input);

           hasNoDoubleSpaces = DoesTheRuleApply(rule1, input);
           isShort = DoesTheRuleApply(rule2, input);
           Console.WriteLine(isShort);
           Console.WriteLine(hasNoDoubleSpaces);
       }

       private static bool DoesTheRuleApply(IStringRule rule, string input)
       {
           return rule.AppliesToString(input);
       }
   }

}

Can anyone please help me to solve it?

Hi, it’s all about the order of these 2 lines. Below is the correct one:

 Console.WriteLine(hasNoDoubleSpaces);
 Console.WriteLine(isShort);

Thank you, Lena :slightly_smiling_face: Sorry, it seems that I tried a lot of options, but this one was not used.