Other 2018 FR Questions FR other years Be Prepared Home
A-3
Part (a)
public class CodeWordChecker implements StringChecker
{
  private int minLength, maxLength;
  private String excluded;

  public CodeWordChecker(int min, int max, String str)
  {
    minLength = min;
    maxLength = max;
    excluded = str;
  }

  public CodeWordChecker(String str)
  {
    minLength = 6;
    maxLength = 20;
    excluded = str;
  } 1

  public boolean isValid(String str)
  {
    return str.length() >= minLength && str.length() <= maxLength && str.indexOf(excluded) == -1;
  } 2
}
Notes:
  1. You can write simply
      public CodeWordChecker(String str)
      {
        this(6, 20, str);
      }
    and receive full credit, even though calling another constructor of the same class using this is not in the AP subset.

  2. Or:
      public boolean isValid(String str)
      {
         if (str.length() < minLength || str.length() > maxLength || str.indexOf(excluded) >= 0)
           return false;
         return true;
      }


Other 2018 FR Questions | Back to Contents

Copyright © 2018 by Skylight Publishing
support@skylit.com