These are my instructions for creating the ants:
Constructor – The constructor should create an ant and give it strength. You can decide how to assign strength. However, one easy way would be to use the built in Random class in order to make the fights fair. Remember, if you aren’t sure how to use a class, read the documentation, post questions to the discussion thread.
int getStrength() - This method should return the ant's strength which should be represented using an integer data member. The ant's strength will be used to determine how an ant performs during a battle. Ants with a high strength value should kill ants with a lower strength value.
IAntBase breed(IAntBase mate) - The breed function should create a new ant whose strength value is calculated based on the strength of its parents. 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. You can be creative if you like and come up with your own way of implementing the breed method.
boolean fight(IAntBase competitor) - This function should compare the competitor's strength to the strength of the current ant ('this'). The strongest ant should win the fight. If the competitor wins then this function would return false otherwise it should return true.
I'm not really sure how to start this, it seems that all of the methods do not have bodies which I have not used yet. Does the code in the IAntBase class need modification or do I create the class that implements it and add code to that? I tried starting with creating an AntBase class that implements IAntBase but it keeps giving me an error.
Here is the template code given to me that is to create the ants:
public interface IAntBase {
public void ant();
/**
* The breed method produces a new ant based on this ant
* and the ant passed as a parameter.
*
* @param mate the ant to use as the other parent for the new child ant.
* @return returns a new child ant based on this ant and mate.
*/
public IAntBase breed(IAntBase mate);
/**
* The fight method makes this ant fight with another ant.
*
* @param enemy the ant that this ant should fight.
* @return true if this ants wins otherwise false.
*/
public boolean fight(IAntBase enemy);
/**
* Returns the strength of this ant.
*
* @return an integer representing this ant's strength.
*/
public int getStrength();
}
class AntBase implements IAntBase{
}

New Topic/Question
Reply



MultiQuote







|