Other 2015 FR Questions FR other years Be Prepared Home
A-4
Part (a)
public interface NumberGroup
{
  boolean contains(int x);
}


Part (b)
public class Range implements NumberGroup
{
  private int minValue, maxValue;

  public Range(int min, int max)
  {
    minValue = min;
    maxValue = max;
  }
  
  public boolean contains (int x)
  {
    return x >= minValue && x <= maxValue;
  }
}


Part (c)
  public boolean contains(int num)
  {
    for (NumberGroup g : groupList)
      if (g.contains(num))
        return true;
        
    return false;
  }

Other 2015 FR Questions | Back to Contents

Copyright © 2015 by Skylight Publishing
support@skylit.com