Jump to content

Anybody take the AP Computer Science exam?


Recommended Posts

I took it and got a 4. I didn’t find it that hard, but its dependant on ability. I learned VB the year before, if you have some programming experience it won’t be too hard.


I had quite a lot of fun messing around with the fish, I tried to give them some simple AI to get them to swim in a school, it didn’t work very well though; they just sort of clumped together. Lol, good times.

Link to comment
Share on other sites

To create unique fish, you would have to extend the fish class and implement its constructors. Then you can create new nextLocation(), move(), and act() methods that define your new fish.


For the knight in particular you could just extend emptyNeighbors() and return an arraylist containing all possible moves that fit the knights movement. I'm pretty sure thats all you need, unless I'm mistaken.

Link to comment
Share on other sites

i don't know how to check two front and one to the right for the knight. Can someone give an example line of code to do so?


So far i've extended the fish class and i've made constructors. I don't know how to do the move and next location. :( I don't have school this week so i don't know how to get help.



Link to comment
Share on other sites

The idea is to use inheritance, so you would just override the methods. it would be the same method header as the super class. For the knight fish, all you would have to do is have the constructors and override the emptyNeighbors() function.


this function gets the locations that you can move to. so you could create an ArrayList(remember to import java.util.*) and add all the possible moves to the ArrayList. An example of this would be:


ArrayList nbrs = new ArrayList();

nbrs.add(new Location(location().row() - 2, location().col() - 1);


you could then take the code at the end of the emptyNeighbors() method from the Fish class and append it to yours. I believe this is the code that is there:

ArrayList emptyNbrs = new ArrayList();

for ( int index = 0; index < nbrs.size(); index++ )


Location loc = (Location) nbrs.get(index);

if ( environment().isEmpty(loc) )




return emptyNbrs;

and there you have it, your first unique fish. One thing to remember, because of inheritance you only have to change a method or two, not all of them. Hope this helps

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.