Other 2011 FR Questions FR other years Be Prepared Home
A-3
Part (a)
  public int nextTankToFill(int threshold)
  {
    int iMin = filler.getCurrentIndex();

    for (int i = 0; i < tanks.size(); i++)
      if (tanks.get(i).getFuelLevel() <= threshold &&
                tanks.get(i).getFuelLevel() < tanks.get(iMin).getFuelLevel()) 1
        iMin = i;

    return iMin;
  }
Notes:
  1. Or <=


Part (b)
  public void moveToLocation(int locIndex)
  {
    int index = filler.getCurrentIndex();
    if (locIndex > index)
    {
      if (!filler.isFacingRight())
        filler.changeDirection();
      filler.moveForward(locIndex - index);
    }
    else if (locIndex < index)
    {
      if (filler.isFacingRight())
        filler.changeDirection();
      filler.moveForward(index - locIndex);
    }
  }

Other 2011 FR Questions | Back to Contents

Copyright © 2011 by Skylight Publishing
support@skylit.com