Ap Computer Science

<p>show wat u did, i only see the first line : )</p>

<p>Esplin im sorry to tell you, but that program is extremely flawed</p>

<p>: / Im not surprised. Which part is the most flawed? Oh and BTW, i know some of the calls are not right.</p>

<p>Oh and i edited where the for-loop goes.</p>

<p>extends Critter should not have a () after it.</p>

<p>for(int i=stockpile; i>0; i–){
super(act);
setstockPile();
}
if(stockPile==0){
removeSelfFromGrid();
}
that is not even in a method.</p>

<p>you were supposed to overwrite the methods of Critter.
the int stockpile should be private.
the constructor ( to my knowledge) should not have taken any paramaters.</p>

<p>I’m pretty sure this is what i did for FRQ #1 on the AB exam. I may have wrote part b slightly differently, but same general idea.</p>

<p>a)



private static void expandNode(TreeNode t){
   TreeNode nRight = new TreeNode(t.getValue(), null, t.getRight());
   TreeNode nLeft = new TreeNode(t.getValue(), null, t.getLeft());
   t.setRight(nRight);
   t.setLeft(nLeft); 
}

b)



private static void growTreeHelper(TreeNode current, Object val){
   if(current != null){
      TreeNode temp1 = new TreeNode(current.getLeft());
      TreeNode temp2 = new TreeNode(current.getRight());
      if(current.getValue().equals(val)){
         expandNode(current);<br>
      }
      growTreeHelper(temp1, val);
      growTreeHelper(temp2, val);
   }
}


</p>

<p>c) expandNode is O(1), growTreeHelper is O(n)</p>

<p>Wait a minute, I thought we couldn’t override the act method AT ALL???
Was that supposed to be a method?
It didn’t explicitly say that the constructor was supposed to take in any parameters. (after all, you want the critter to have a chance to move around right?)</p>

<p>lol my bad im used to java so i tabbed it to make it more clear but evidently
cc doesnt allow tabbing on empty lines. instead it like removes the typing cursor
away so i tried it with the space bar which made it post what u saw
but i fixed it now</p>

<p>umm dang for AP Comp sci AB #1, I kinda got right, but I had way too many lines of code…but I think it ends up doing almost the same thing.</p>

<p>For number 3, did you guys run out of space? I didnt finish number 2 completely because I was trying to erase and fit everything into the tiny space for number 3…</p>

<p>Anyone know (besides Barrons curve) what the usual score out of 100 is needed for a 4 on Comp Sci? 50? 55? 60?
Its AB, so shouldnt the curve be a little more lenient? Like BC is a lot easier than AB calc.</p>

<p>for A people:</p>

<p>i just overrode the processActors() method and i added a constructor to initialize my stockpile arraylist</p>

<p>Again, this is just what I did (or close to it). By no means is this the only answer, or even a correct answer.
a) I actually will get a point or two off on this one because i forgot to satisfy one of the post-conditions. Anyways, i included the line of code here that checks if the location you are moving to is different from the current location just to make this answer complete.



public void makeMove(Location loc){
   if(loc == null)
      removeSelfFromGrid();
   else{
      if(!(loc.equals(get.Location()))){
         if(places.containsKey(loc))
            places.put(loc, new Integer(places.get(loc).intValue() + 1));
         else
        places.put(loc, new Integer(1));
      }
      moveTo(loc);
   }
}

b) Again i made a small mistake (i think). On the actual exam I believe I wrote HashSet a = places.keySet() --- but i don't think that is a valid statement. Here i simply declare the set "a" to be of type Set. There is probably a more efficient way than iterating through the entire set of locations twice, but I was just too lazy to think of it during the test



public List<location> mostPopularPlaces(){
   List<location> result = new ArrayList<location>();
   Set<location> a = places.keySet();
   int max = 0;
   for(Location loc: a){
      if(places.get(loc).intValue() > max)
         max = places.get(loc).intValue();
   }
   for(Location b: a){
      if(places.get(b).intValue() == max)
         result.add(b);
   }
   return result;
}


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

<p>I’m relatively inexperienced at Comp Sci (I taught myself the material, because the course won’t be offered at my school next year). If I had just called getTreeHelper on the left and right nodes, then checked the root (in a post order traversal sort of way), would that also produce the correct result? Or did I overlook something? Thanks.</p>

<p>for AB yay i think i did something very similar to both of those so i’m happy already. :slight_smile:
i fail at big oh though. but at least that problem’s probably worth like… only 1 point. hehe</p>

<p>now i feel like number 2 i was unsure, and number 3 mine was really simple >.< and number 4 was the really lengthy and weird one. hmmm</p>

<p>3rd entry out of 4 =). This is all from memory, i’m just retyping it now. If you see some error (such as a missing ; ) feel free to point that out, but those types of errors probably only happened just now and not on the test itself (i hope). Also, if you answered a question in a different way i’d like to hear how you did it (i am still learning too :stuck_out_tongue: )</p>

<p>edit: i meant for it to return Integer.MAX_VALUE if temp was too large



public Class ArithmeticNumberStream implements IncreasingNumberStream{
   private int next;
   private int init;
   private int increment;</p>

<p>public ArithmeticNumberStream(int initial, int inc){
      init = initial;
      next = initial;
      increment = inc;
   }</p>

<p>public int nextTerm(){
      int temp = next;
      if(temp > Integer.MAX<em>VALUE){
         return Integer.MAX</em>VALUE;
      }
      next = next + increment;<br>
      return temp;
   }</p>

<p>public void restart(){
      next = init;
   }
}

</p>

<p>well i think what i wrote is similar to yours (AB) so that’s good! i think i added unnecessary code but it doesn’t affect the output so it shouldn’t be taken off. although semicolons are nonpenalized errors so don’t worry about those!</p>

<p>Some one type question number 3 for the A exam please</p>

<p>final entry :P. This one seemed complicated at first, but i think it worked out fairly nicely.</p>

<p>a) I almost messed up and forgot to add the line result.add(a) on the test. luckily i caught myself. It essentially adds all of the contacts who are distance 1 away. If you exclude it, you are only guaranteed the contacts who are distance 2 away (though some may also be distance 1 away, if that makes any sense)



private static Set<person> expandContanctSet(Set<person> people){
   Set<person> result = new HashSet<person>();
   for(Person a: people){
      result.add(a);
      Set<person> b = a.getContacts();
      for(Person c: b){
         result.add(c);<br>
      }
   }
   return result;
}


b) I like how simple this was thanks to part a lol.



public Set<person> getNetwork(int dist){
   Set<person> a = getContacts();
   for(int i = 1; i < dist; i++){
      a = expandContactSet(a);
   }
   return a;
}

</person></person></p>

<p>oh sheez i feel a fail coming along for question 4 for me. -_- i’m pretty sure i forgot that call for distance 1 away people, and i know my part b code was not that simple. :(</p>

<p>i want my green paper thingy back so i can for sure know what i put… >_<</p>

<p>i forgot what i did for number 3, but did anyone set the initial cost to 3200*((startTime + chargeTime) % 24)</p>

<p>b/c you have to include the total day if chargeTime > 23</p>

<p>hum… well my #4(b) code did the same thing as yours, I just missed the fact that I could simplify it so much. So it is more code + horribly inefficient. I wonder how many points they’ll take off for that.</p>

<p>I feel your pain. For some weird reason, I completely forgot about part a, so I repeated most of the code from part a, and had to have a temp Set to make it all work. While I liked my solution, it does show how efficient the methods they give you are. I’m pretty sure I’m going to lose a fair amount of points for reusing code, but nothing I can do about it now…</p>