LAST FRQ

2017 1

      Part a
      public Digits(int num)
      {
        digitList = new ArrayList();
          while (num > 0)
          {
            digitList.add(0, num % 10);
            num /= 10;
          }
          if (digitList.size() == 0)
          digitList.add(0);
        }
      Part b
      public boolean isStrictlyIncreasing()
      {
        for (int k = 1; k < digitList.size(); k++)
        if (digitList.get(k).intValue() <= digitList.get(k-1).intValue())
        return true;
      }
      

2018 1

Part A public boolean simulate() { int pos = 0; for (int hops = 0; hops < maxHops; hops++) 1 { pos += hopDistance(); if (pos >= goalDistance) return true; else if (pos < 0) return false; } return false; } Part B public double runSimulations(int num) { int count = 0; 1 for (int n = 0; n < num; n++) if (simulate()) count++; return (double)count / num; }

2012 4

Part a public int countWhitePixels() { int count = 0; for (int r = 0; r < pixelValues.length; r++) for (int c = 0; c < pixelValues[0].length; c++) if (pixelValues[r][c] == WHITE) 1 count++; return count; } Part B public void processImage() { for (int r = 0; r < pixelValues.length - 2; r++) for (int c = 0; c < pixelValues[0].length - 2; c++) pixelValues[r][c] = Math.max(BLACK, pixelValues[r][c] - pixelValues[r+2][c+2]); }

2011 1

Part a private void fillBlock(String str) { int i = 0; for (int r = 0; r < numRows; r++) { for (int c = 0; c < numCols; c++) { if (i < str.length()) letterBlock[r][c] = str.substring(i, i+1); else letterBlock[r][c] = "A"; i++; } } } Part b public String encryptMessage(String message) { String code = ""; while (message.length() > 0) { int n = numRows * numCols; if (n > message.length()) n = message.length(); 1 fillBlock(message.substring(0, n)); 2 code += encryptBlock(); message = message.substring(n); } return code; }

2010 1

Part a public int getTotalBoxes() { int total = 0; for (CookieOrder o : orders) total += o.getNumBoxes(); return total; } Part b public int removeVariety(String cookieVar) { int total = 0; for (int i = orders.size() - 1; i >= 0; i--) { CookieOrder o = orders.get(i); if (o.getVariety().equals(cookieVar)) { total += o.getNumBoxes(); orders.remove(i); } } return total; }

2009 4

Part a private int getIndexForFit(NumberTile tile) { if (board.size() == 0 || tile.getRight() == board.get(0).getLeft()) return 0; if (tile.getLeft() == board.get(board.size() - 1).getRight()) return board.size(); for (int i = 1; i < board.size(); i++) { if (tile.getLeft() == board.get(i-1).getRight() && tile.getRight() == board.get(i).getLeft()) return i; } return -1; } Part b public boolean insertTile(NumberTile tile) { for (int count = 1; count <= 4; count++) { int i = getIndexForFit(tile); if (i >= 0) { board.add(i, tile); 1 return true; } tile.rotate(); 2 } return false; }