Other 2008 FR Questions FR other years Be Prepared Home
A-4
Part (a)
public class SubstringChecker implements Checker
{
  private String substr;

  public SubstringChecker(String s)
  {
    substr = s;
  }

  public boolean accept(String text)
  {
    return text.indexOf(substr) >= 0;
  }
}

Part (b)
public class AndChecker implements Checker
{
  private Checker checker1, checker2;

  public AndChecker(Checker c1, Checker c2)
  {
    checker1 = c1;
    checker2 = c2;
  }

  public boolean accept(String text)
  {
    return checker1.accept(text) && checker2.accept(text);
  }
}

Part (c)
    yummyChecker = new AndChecker(new NotChecker(aChecker), new NotChecker(kChecker));

Other 2008 FR Questions | Back to Contents

Copyright © 2008 by Skylight Publishing
support@skylit.com