Homework 9 (Critters) FAQ

Q: How do I get started?

A: Download the three provided files. Compile and run CritterMain.java to see if the basic simulator works. Then copy/paste the contents of Stone.java into a new file and save it as Ant.java. Then you can modify the code to try to implement that animal.

Q: When I try to run my Stone or other animals, I get the following error. Why?

Exception in thread "main"
java.lang.NoSuchMethodError: main

A: Don't run the animal classes. Run CritterMain.

Q: Why can't I use a for loop for my critter's movement? Without a loop, how will I make the critter move multiple times in a given pattern?

A: This is one of the toughest aspects of object-oriented programming: accepting that your object is no longer in control of the overall program. In Critters, the simulator asks each animal for a single move at a time. You can only return one move, so your critter object must keep track of what should be returned next time. By declaring the right set of fields in each object and giving them the appropriate values, your object can "remember" information that will tell it what to do in future moves.

Q: I can pick a random direction once, but how do I move in the *same* random direction multiple times?

A: Try picking a random direction and then having your object "remember" that direction. How do we make objects "remember" things?

Q: How do we use a value that's passed in to the constructor, in another method of that class?

A: Make the object "remember" that value for use later. How do we make objects "remember" things?

Q: Why am I getting compiler errors about Point (or some random Java file)?

A: You are probably saving all of your programs into the same directory that has a Point.java file. Put your Critters program files into their own directory.


Q: My CritterMain chokes with lots of compiler errors.

A: Make sure that you have copied over the entire file from the web site by right-clicking and choosing "Save As" instead of only copying and pasting part of the file.

Q: I tried to change color/toString/fight/etc. and it compiles, but when I run I still get the default behavior!

A: Check to make sure the method headers exactly match what is expected. Classes with methods such as getcolor (capitalized improperly) or getColor(String critter) (incorrect parameters) will compile but will be silently ignored; methods with incorrect headers will not properly override the methods from Critter.java.

Q: Is my Husky "creative" enough?

A: We won't pre-judge your Husky for you, but if you follow the guidelines on the assignment writeup and implement a new set of behavior that is distinct from all the other provided critters, you should be fine.