OFFICIAL 2012 AP Computer Science A Thread

<p>and for problem 4 part b</p>

<p>public void processImage()
{
for(int i=0;i<pixelValues.length-2;i++)
{
for(int j=0;j<pixelValues[0].length-2;j++)
{
if((pixelValues*[j]-pixelValues[i+2][j+2])<0)
pixelValues*[j]=BLACK;
else
pixelValues*[j]=pixelValues*[j]-pixelValues[i+2][j+2];
}}}</p>

<p>Quick question; does a for each loop hit null spaces?</p>

<p>My theory for consolidate was this:</p>

<p>ArrayList<horse> temporary = new ArrayList<horse>();
for (Horse b: spaces)
{
if (b instanceof Horse)
{
temporary.add(b);
}
}</horse></horse></p>

<p>int dif = spaces.size() - temporary.size();
for (int i = 0; i < dif; i++)
{
temporary.add(null);
}</p>

<p>spaces = temporary;</p>

<p>@bigvinu yes an enhanced for loop will iterate over null spaces. however, null instanceof horse will return false (will not generate a nullpointerexception)</p>

<p>I thought that the MC had way too much tracing. Anyone agree with me?</p>

<p>@Bigvinu I don’t think that you can assign spaces (private Horse[]) an ArrayList<horse>.</horse></p>

<p>Would this work for (1)(b)?:</p>

<p>ClimbInfo climb = new ClimbInfo(peakName, climbTime);
int index = climbList.size()-1;
for(int i = 0; i<climbList.size(); i++){
if(climb.getName().compareTo(climbList.get(i).getName())<0){
index = i;
break;
}
}
climbList.add(index, climb);
}</p>

<p>@aweaweg: the chief question is always “does it work”. The choice of what method to override usually isn’t the issue … unless, as you point out, the choice of method means that it doesn’t always work. :)</p>

<p>@defianced: both of those look right. (The first time I tried consolidate(), I wrote a very similar bubble-sort-esque algorithm.)</p>

<p>@bigvinu: like @njdevs, I’m concerned that the last line won’t work … I don’t think there’s an automatic conversion from ArrayList to arrays.</p>

<p>@ckfy63a: I think you need to initialize index to climbList.size(), not climbList.size()-1. Otherwise, there’s no way to add an item to the very last position in the list.</p>

<p>@jkhuggins: But wouldn’t that get an ArrayIndexOutOfBoundsException? Let’s say climbList.size() was 6, then index 6 would be out of bounds, yes?</p>

<p>@jkhuggins, ok I see. So would that be like one point off? (I know the scoring guidelines haven’t been created yet, but just wondering)</p>

<p>@ckfy63a, I think jkhuggins is right. If you add a ClimbInfo object to the list at climbList.size()-1, that would mean the added object is the second-to-last object in the list when you want it to be the last. The method throws an ArrayIndexOutOfBoundsException if index > size(), according to [the</a> documentation](<a href=“JDK 20 Documentation - Home”>JDK 20 Documentation - Home), so index = size() is ok.</p>

<p>@aweaweg: Ah, I see now. Thanks for the clarification. I was thinking of Arrays as opposed to ArrayList. How many points would they deduct for that then?</p>

<p>@aweaweg and @ckfy63a: even without knowing the rubric, it’s hard to say … it all depends on how many things get affected by the error. Rubrics tend to be written in terms of 10-20 “local features” that need to be correctly present in every correct solution, with each feature being assessed 0.5-1.0 points. A lot of the errors we’ve discussed, like @ckfy63a’s loop bound problem, tend to only affect one local feature and thus end up as just 0.5-1.0 point deductions. Something more systematic, like @aweaweg’s choice of methods to override, <em>might</em> end up affecting multiple local features, and so <em>might</em> end up with more deductions, depending on exactly how things get fouled up in general.</p>

<p>I realize that sounds vague … but it’s hard to say much more than that. Each problem is different. (Insert usual disclaimers here …)</p>

<p>@jkhuggins, Ok thanks for the elaboration.</p>

<p>Just wondering: when do you actually go to Colorado (that’s what my teacher says) to grade these things?</p>

<p>Actually, APCS is graded in Cincinnati. (There are five different grading sites; different exams are graded in different places.) The APCS reading this year is June 2-8. Leaders will show up a few days earlier.</p>

<p>In the Gridworld problem, I didn’t set prevLoc and prevDir to the current location and direction until inside the overridden act method (before calling super.act()). I failed to see that this would generate an error if restore was called before act has been. I know a bunch of my classmates did the same as well. Does that seem like a one point deduction?</p>

<p>I think I did the least efficient alphabetizing of all time for 1b (I have no idea why I wrote code as if the other peaks weren’t already in order, but it ended up with many lines of code and two for loops. Whoops!), but I doubt I’ll lose points for general foolishness.</p>

<p>When consolidating horses, do you think the following would work: using a for loop to find the total number of horses in the barn, using a for loop that swaps a horse with an empty stall if the stall’s index is one less than the horse’s, and a recursive call of consolidate if there are any empty stalls between index 0 and totalNumHorses-1 (to account for one for loop not being enough if there are consecutive empty stalls).</p>

<p>I can’t remember whether I put an if statement setting pixelCount to 0 if it was negative or not. This is really going to bother me, seeing as the latter would probably result in a fairly large deduction.</p>

<p>Thanks for any feedback! I know I should just wait for my official score and not freak out or become addicted to CC, but I’m really nervous because I only get credit for a 5, which is tough for a novice programmer to get when so many peers have years of experience.</p>

<p>Would this work for consolidate? </p>

<p>Horse [] temp=new Horse[spaces.size];
int k=0;</p>

<p>for (int i=0; i<spaces.size; i++){</p>

<pre><code>if (spaces*!=null){

temp[k]=spaces*;
k++;

}
</code></pre>

<p>}</p>

<p>spaces=temp;</p>

<p>Because all the spaces in temp that weren’t filled with a Horse object should by default be null, correct?</p>

<p>@killerskullz</p>

<p>Horse[] temp = new Horse[spaces.length]; but I think that would be a minor deduction (I’m not an AP grader…)</p>

<p>That’s a good algorithm, however, and I believe that you would get full or close to full marks for it.</p>

<p>nvm 10char</p>

<p>Hey guys, I tried looking this up, but I couldn’t find anything. For the horse question I treated spaces as an arraylist instead of an array. Does anyone know what the penalty will be?</p>