sullivanf
February 28th, 2000, 06:23 AM
Hello all
Please check out the following
Assignment #3 - The Ant Farm
Part 1 - Create An Ant
Part 2 - Create A Colony
Part 3 - Create A Second Type Of Ant
Part 4 - Submit Your Assignment
Part 1 - Create An Ant
The first part of this weeks assignment is to create a subclass of the AntBase abstract class. To do this, get the
code for the AntBase class from lecture 3-9 and then create a new class that extends the AntBase class. Place
this new class under your base path in a new package called CrazyAnts.
Since the AntBase class is an abstract class you must override all of its methods. Here are some suggestions
for implementing your ant:
int strength() - This method should return the ant's strength which should be represented using an integer. The
ant's strength will be used to determine how an ant performs during a battle. Ant's with a high strength value
should kill ants with a lower strength value.
AntBase breed(AntBase mate) - The breed function should create a new ant whose strength value is
calculated based on its parents strenght. For example all baby ants could be created with the strength of the
strongest parent or they could be created with the average strength of the two parents. This way offspring of
strong parents will also be strong.
boolean fight(AntBase victim) - This function should compare the victim's strength to the strength of 'this'.
The strongest ant should win the fight. If the victim wins then this function would return false otherwise it should
return true.
Keep in mind this is just to give you an idea of how to implement these functions. You may implement them
differently if you like. In addition all of the coding standards apply. Add docomments, the unit test
function we discussed, the toString() method, and any other standard methods that you think should
be implemented. In addition, use the Debug class you wrote in assignment #2 liberally.
Part 2 - Create A Colony
The second part of this assignment is to create a subclass of ColonyBase. To do this, get the code for
ColonyBase from lecture 3-10 and then extend the ColonyBase class. Since the ColonyBase class is an
abstract class you must override all of its methods. Place this new class under in the CrazyAnts package. Here
are some suggestions for implementing your colony:
Constructor - The constructor should take a size as a parameter and then fill the colony up with that many ants.
int size() - This function should return the number of ants in the colony.
AntBase getAnt(int index) - This function should return an AntBase that is located in the colony at the
specified index.
void addAnAnt(AntBase antToAdd) - This function should add an ant to the colony.
void killAnAnt(AntBase antToKill) - This function should remove an ant from the colony.
void regenerate() - This function should loop through all the ants in the colony and have them breed with each
other. Baby ants created should be added to this colony.
void attack(ColonyBase victim) - This function should loop through all the ants in the victim's colony and
attack them with an ant in this colony. If an ant looses a battle then it should be removed from its colony.
Keep in mind this is just to give you an idea of how to implement these functions. You may implement them
differently if you like. When you are done with this part the simulation should be complete. Get the code for
AntFarm from lecture 3-11, run it and see if it works!
Part 3 - Create A Second Type Of Ant
Create a second type of ant and give it a different behavior then the first one you created. For example change
the way it breeds or change the way it fights. Perhaps it has an attack bonus that is added to its strenght at
random intervals. Then change the simulation so that it will use a colony of each type of ant. Be sure to keep
track of what you had to change in order to get the simulation to work with the new ant type. This is
important because we will use this as a measure of how good our design is. In addition, we will be
improving this design with a design pattern later on that will make adding new ants even easier.
Part 4 - Submit Your Assignment
Submit the following:
1.The AntBase class.
2.Your first ant class.
3.The ColonyBase class.
4.Your colony class.
5.Your second ant class.
6.The AntFarm class.
7.The javadoc generated HTML files for all of you packages, including the new CrazyAnts package.
8.A description of what you had to change in order to use both types of ants.
Be sure to create the new package, add docomments, add toString() methods, add unit test functions, and use
your Debug class!
Take your time and do it right. This assignment is not due until march first!
Please check out the following
Assignment #3 - The Ant Farm
Part 1 - Create An Ant
Part 2 - Create A Colony
Part 3 - Create A Second Type Of Ant
Part 4 - Submit Your Assignment
Part 1 - Create An Ant
The first part of this weeks assignment is to create a subclass of the AntBase abstract class. To do this, get the
code for the AntBase class from lecture 3-9 and then create a new class that extends the AntBase class. Place
this new class under your base path in a new package called CrazyAnts.
Since the AntBase class is an abstract class you must override all of its methods. Here are some suggestions
for implementing your ant:
int strength() - This method should return the ant's strength which should be represented using an integer. The
ant's strength will be used to determine how an ant performs during a battle. Ant's with a high strength value
should kill ants with a lower strength value.
AntBase breed(AntBase mate) - The breed function should create a new ant whose strength value is
calculated based on its parents strenght. For example all baby ants could be created with the strength of the
strongest parent or they could be created with the average strength of the two parents. This way offspring of
strong parents will also be strong.
boolean fight(AntBase victim) - This function should compare the victim's strength to the strength of 'this'.
The strongest ant should win the fight. If the victim wins then this function would return false otherwise it should
return true.
Keep in mind this is just to give you an idea of how to implement these functions. You may implement them
differently if you like. In addition all of the coding standards apply. Add docomments, the unit test
function we discussed, the toString() method, and any other standard methods that you think should
be implemented. In addition, use the Debug class you wrote in assignment #2 liberally.
Part 2 - Create A Colony
The second part of this assignment is to create a subclass of ColonyBase. To do this, get the code for
ColonyBase from lecture 3-10 and then extend the ColonyBase class. Since the ColonyBase class is an
abstract class you must override all of its methods. Place this new class under in the CrazyAnts package. Here
are some suggestions for implementing your colony:
Constructor - The constructor should take a size as a parameter and then fill the colony up with that many ants.
int size() - This function should return the number of ants in the colony.
AntBase getAnt(int index) - This function should return an AntBase that is located in the colony at the
specified index.
void addAnAnt(AntBase antToAdd) - This function should add an ant to the colony.
void killAnAnt(AntBase antToKill) - This function should remove an ant from the colony.
void regenerate() - This function should loop through all the ants in the colony and have them breed with each
other. Baby ants created should be added to this colony.
void attack(ColonyBase victim) - This function should loop through all the ants in the victim's colony and
attack them with an ant in this colony. If an ant looses a battle then it should be removed from its colony.
Keep in mind this is just to give you an idea of how to implement these functions. You may implement them
differently if you like. When you are done with this part the simulation should be complete. Get the code for
AntFarm from lecture 3-11, run it and see if it works!
Part 3 - Create A Second Type Of Ant
Create a second type of ant and give it a different behavior then the first one you created. For example change
the way it breeds or change the way it fights. Perhaps it has an attack bonus that is added to its strenght at
random intervals. Then change the simulation so that it will use a colony of each type of ant. Be sure to keep
track of what you had to change in order to get the simulation to work with the new ant type. This is
important because we will use this as a measure of how good our design is. In addition, we will be
improving this design with a design pattern later on that will make adding new ants even easier.
Part 4 - Submit Your Assignment
Submit the following:
1.The AntBase class.
2.Your first ant class.
3.The ColonyBase class.
4.Your colony class.
5.Your second ant class.
6.The AntFarm class.
7.The javadoc generated HTML files for all of you packages, including the new CrazyAnts package.
8.A description of what you had to change in order to use both types of ants.
Be sure to create the new package, add docomments, add toString() methods, add unit test functions, and use
your Debug class!
Take your time and do it right. This assignment is not due until march first!