*** OFFICIAL 2013 AP Computer Science A Thread***

<p>For part (b) would this be valid:</p>

<p>public void addClimb(String peakName, int climbTime)
{
int index = 0, k = 0;
while( index == 0 && k < climbList.size() )
{
if( climbList.get(k).getString().compareTo(peakName) > 0 )
{
index = k;<br>
}
}
climbList.add(index, new ClimbInfo(peakName, climbTree ) );
}</p>

<p>Thanks!</p>

<p>What problem?</p>

<p>help!! do i have to know all of the terms used in Barron’s chapter 5 Program Design and Analysis?</p>

<p>Someone want to clarify something for me? This is really confusing:</p>

<p>So in Java all parameters are passed by value, correct? However, when an object is passed, the reference is copied, not the value. This won’t change the actual variable, however, just the parameter. Yet with arrays, which are treated as objects, you can modify the elements when the array itself is passed as the parameter. How does this work if objects aren’t supposed to be modified when passed as a parameter?</p>

<p>can someone please please explain to me clearly how critter and chameleoncritter work? or not really how they work but what they do
i don’t understand them</p>

<p>@ AK Shockwave: the only things where objects are made into copies when passed into another object are Strings and primitive data types. For example</p>

<p>public void class (){</p>

<p>int x = 9;
int y = 0;
eatMe(x,y);
System.out.println(x + “,” + y);
}</p>

<p>public void eatMe( int m, int n){
m = m +5;
n = n+ 4;
System.out.println(m + “,” + n );}</p>

<p>it would show this:
13,4
9,0</p>

<p>for objects, instead of creatin a whole new copy, what happens is that they just make the variable being passed in point to the object. so</p>

<p>public void class (){</p>

<p>Object x = 9;
Object = 0;
eatMe(x,y);
System.out.println(x + “,” + y);
}</p>

<p>public void eatMe( Object m, Object n){
m = m +5;
n = n+ 4;
System.out.println(m + “,” + n );}</p>

<p>thats not exactly how objects work, but i am not a creative person
what would print would be </p>

<p>13,4
13,4
because the Java points it to the same data reference. Therefore if you change something, the data reference would change as well.</p>

<p>@binatang
Critter gets the actors around it (gets an array of actors in its surrounding) and eats the ones taht are not critters or rocks. then it moves in a random direction</p>

<p>ChameleonCritter gets the actors the same way Critter does but instead of eating them it chooses a random one (math.random()) and changes to its color. Then it moves in a random direction.</p>

<p>Thats why ChameleonCritter overrides Critter’s processActors but not Critter’s getActors. They get actors the same way but what they do with them is different.</p>

<p>Here’s a post I made earlier by pass-by-reference/pass-by-value:</p>

<p>

</p>

<p>@nsquared2</p>

<p>i dunno. it doesnt seem like it would work because #1 you don’t increment k and #2 you dont do anything if its the same name. This is what i did.
public void addClimb(String peakName, int climbTime){
if (climbList.size() < 1)
climbList.add(new ClimbInfo (peakName, climbTime));
for (int i = 0; i < climbList.size()-1; i++){
if( climbList.get(k).getString().compareTo(peakName) < 0 && climbList.get(k+1).getString().compareTo(peakName) > 0)
climbList.add(k, new ClimbInfo (peakName, climbTime));
if (climbList.get(k).getString().compareTo(peakName == 0){
if (climbList.get(k).getTime > climbTime)
climbList.add(k, new ClimbInfo (peakname, climbTime));
else
climbList.add(k+1, new ClimbInfo (peakname, climbTime));
}
}
}</p>

<p>i know its kind of really inefficient and stuff and a lot to compile in your head but this is what i have. im sorry if there are errors but im pretty sure that they are not major.</p>

<p>hopefully there wont be any 2D arrays and minimal GridWorld on the FRQ’s</p>

<p>2D arrays aren’t too bad. just do loop within loop and don’t forget how to find out the length. array.length and array[x].length i believe! </p>

<p>Good thing we get the Quick Reference for GridWorld! I hope we don’t need to write any classes… calling the supers confuse me</p>

<p>Gridworld in general is just annoying lol</p>

<p>So basically with primitives the value is copied and with objects the address is copied? Meaning you can change an object passed as a parameter? Unless it’s something like this: </p>

<p>public void changeIt(int[] list, int num) {
list = new int[5];
num = 0;

}</p>

<p>public void start() {
int[] nums = {1, 2, 3, 4, 5};
int value = 6;</p>

<p>changeIt(nums, value);

}</p>

<p>This is question 36 from the 2009 test; it’s what sparked all this confusion for me. So basically the arguments are nums and value, but then in change it you reassign list to new int[5] — yet this does not affect nums because list is a separate reference to the same array, and redeclaring list makes it a separate reference to a separate (new) array, correct? </p>

<p>And value obviously won’t change because it’s a primitive. That parts easy.</p>

<p>If my reasoning is correct up there though, then I think I finally understand what’s going on here. I swear this is like the only part of the course I don’t get.</p>

<p>yes. you should be right
its because the “new” makes a new location to refer to.</p>

<p>@AKShockwave
You got it! :D</p>

<p>look at it like this: (view comments in code)</p>

<p>public void changeIt(int[] list, int num) {
list = new int[5];
num = 0;

}</p>

<p>public void start() {
int[] nums = {1, 2, 3, 4, 5}; // let’s give this bby an address of 63.
int value = 6;</p>

<p>changeIt(nums, value);

}</p>

<p>So from what I stated, nums ‘has’ an address of 63. Let’s take an in-depth look at what the method does exactly.</p>

<p>public void changeIt(int[] list, int num) {
list = new int[5]; // creates a ‘new’ “reference”. as a result, the address is changed. let’s say the address is 92. Now because the list argument now refers to a completely different array object, it will not affect the list given within the params. However, if the ‘new’ statement wasn’t there, then we would be able to actually modify the orig. array inputted as the argument for the params.
num = 0;

}</p>

<p>imo, recursion within recursion and manipulating 2-D arrays is the hardest part. <_></p>

<p>Whatsup guys?
Just back from Computer Science A (India)</p>

<p>Just a booster - It was the shortest and easiest paper ever!</p>

<p>Wish I could ask if the grid world mc and frq were hard >.>. I’m taking it in 90 mins ^.^</p>

<p>Agreed. Took the test in China, and it was so easy that I almost regret that I spent so much time reviewing Comp sci instead of other exams…</p>

<p>Rabbit, how was each section?</p>

<p>Rabbit, wasn’t the FRQ hard? Cuz that’s what I thought. But again, I never reviewed for Comp Sci FRQ.</p>

<p>Guys (those who are done), please, can you give me your earnest opinions? I just took the Comp Sci AP. And these are my thoughts: minimum, minimum, minimum 25-30 right on MC. On FRQ, I messed up big time; although I answered everything, I wasn’t sure of any line I was writing, especially for the JumperCritter. If I get things right, it’s because I used same names as the header or smthn lol. I’m quite sure my code wouldn’t work, and plus, I just wrote whatever came to my mind. I didn’t grasp the questions very strongly.
Should I cancel the AP test? Problem is that I studied for Comp Sci quite a bit; I read the Barron’s twice and took notes, and that’s why I think I did pretty well in the MC portion. But, honestly, what do you think I should do?</p>

<p>ccuser001, you did fairly well on the multiple choice, I wouldn’t cancel it if I were you :)</p>