2011 Computer Science Test Thoughts

<p>i would post number one but i don’t really remember the question, but i know for a fact i got it. Also, if you didn’t do this.array.length, you would lose 1/2 a point, since the array was private. This was also true for the 2010 exam. I am just saying that since most peopel forgot that.</p>

<p>Uhh you don’t have to specify the “this” object due to the variable’s scope (it has nothing to do with the access level of the variable). The program will compile and run fine, it isn’t a bug.</p>

<p>@hollyandphoenix: If you answered everything correctly, my rough guesstimations put you at a definite 3. Counting in for stupid mistakes/wrong answers, you have a decent chance of getting a 3.</p>

<p>@zrathustra look at free response 2010, all of the private arrays had “this.”, it said on the rubric for the 2010 that you lose 1/2 a point for it.</p>

<p>CSMathAsa1994: if you look at the sample responses for the 2010 free response, the perfect response to #1 didn’t have “this” on it.</p>

<p>CSMathAsa1994:</p>

<p>It doesn’t seem to be on the 2010 scoring guidelines. I doubt that they would require it, considering that it is only required in a few specific cases which didn’t even appear on the exam.</p>

<p><a href=“Supporting Students from Day One to Exam Day – AP Central | College Board”>Supporting Students from Day One to Exam Day – AP Central | College Board;

<p>Those are the 2011 questions if people want to start sharing how they solved them.</p>

<ol>
<li>a)</li>
</ol>

<p>


public int limitAmplitude(int limit) {
    int changes = 0;
    for (int i = 0; i < samples.length; i++) {
        if (samples* > limit) {
            changes++;
            samples* = limit;
        } else {
            if (samples* < -limit) {
                changes++;
                samples* = -limit;
            }
         }
    }
    return changes;
}

</p>

<ol>
<li>b)</li>
</ol>

<p>


public void trimSilenceFromBeginning() {
    int firstSound = 0;
    for (int i = 0; i < samples.length; i++) {
        if (samples* != 0) {
            firstSound = i;
            break;
        }
    }
    int[] newSamples = new int[samples.length - firstSound];
    for (int i = 0; i < newSamples.length; i++) {
        newSamples* = samples[i + firstSound];
    }
    samples = newSamples;
}

</p>

<p>I feel like there was probably a more elegant way to do that one…</p>

<p>AndrewT: For 1b, there’s a slightly “easier” way. I initialized my counter “int n” outside of the first for loop so when the first value of samples[n] != 0, I had that variable readily available for use in my next loop (which used a different counter, which I initialized in the header of the loop this time). I just had to increment n++ at the bottom of my second loop, so the second loop looked something like this:</p>

<p>for (int j = 0; j < newSamples.length; j++) {
newSamples[j] = samples*;
i++;
}</p>

<p>It’s not really easier, it just made everything much cleaner, in my opinion.</p>

<ol>
<li>a)</li>
</ol>

<p>


public int nextTankToFill(int threshold) {
    int minIndex = filler.getCurrentIndex();
    for (int i = 0; i < tanks.size(); i++) {
        if (tanks.get(i).getFuelLevel() < threshold) {
            if (tanks.get(i).getFuelLevel() < tanks.get(minIndex).getFuelLevel()) {
                minIndex = i;
            }
        }
    }
    return minIndex;
}

</p>

<ol>
<li>b)</li>
</ol>

<p>


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

</p>

<ol>
<li>a)</li>
</ol>

<p>


private void fillBlock(String str) {
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numCols; col++) {
            int index = row * numCols + col;
            if (index >= str.length())
                letterBlock[row][col] = "A";
            else
                letterBlock[row][col] = str.substring(index, index + 1);
        }
    }
}

</p>

<ol>
<li>b) (credit goes to Cifer for this shortened version)</li>
</ol>

<p>


public String encryptMessage(String message) {
    String encrypted = "";
    for (int i = 0; i < message.length(); i += numRows * numCols)
    {
         fillBlock(message.substring(i));
         encrypted += encryptBlock();
    }
    return encrypted;
}

</p>

<ol>
<li></li>
</ol>

<p>



public class AttractiveCritter {
    public ArrayList<actor> getActors() {
        ArrayList<actor> actors = new ArrayList<actor>;
        ArrayList<location> locs = getGrid().getOccupiedLocations();
        for (Location loc : locs) {
            Actor a = getGrid().get(loc);
            if (a != null && a != this) {
                actors.add(a);
            }
        }
        return actors;
    }
    public void processActors(ArrayList<actor> actors) {
        for (Actor a : actors) {
            Location loc = a.getLocation();
            Location myLoc = getLocation();
            int dir = loc.getDirectionToward(myLoc);
            Location newLoc = loc.getAdjacentLocation(dir);
            if (getGrid().get(newLoc) == null) {
                a.moveTo(newLoc)
            }
        }
    }
}

</actor></location></actor></actor></actor></p>

<p>I think I got 2 mostly right… I just forgot to “a != this” so that it wouldn’t try to move itself… or would that even make a difference?</p>

<p>Out of curiosity, how much do you think I will lose for writing this as the getActors() method in the Grid World Class (assuming my other method/class structure was correct):</p>

<p>



public ArrayList<actor> getActors() {</actor></p>

<p>return getGrid().getOccupiedLocations();</p>

<p>}


</p>

<p>^apcalc1</p>

<p>Did you handle the fact that it was just positions in the processActors() or just ignore it?</p>

<p>If you ignored it then you pretty much just missed half of the program.</p>

<p>TheForbes:</p>

<p>I’m not entirely sure. If an AttractiveCritter tried to process itself, then it would end up calling loc.getDirectionToward(loc) which would definitely cause problems of some kind. I can’t imagine that hurting you very much, though.</p>

<p>hey according to the appass calculator why do most ap exams such as ap euro have a 66% or so for a 5, ap bio has like a 62% for a 5, but comp sci has a 78% for a 5? What’s up with that?</p>

<p>Thanks AndrewT.</p>