Define an Animal method that updates the time to complete a particular behavior based on its name. Choose one of the following from the above choices (A, B, C or D within the code):
Define an Animal method that updates the time to complete a particular behavior based on its name.
Choose one of the following from the above choices (A, B, C or D within the code):
public class Animal {
// Other instance variables, constructors and methods
// omitted for brevity
// A
public void updateTimeTakenForBehavior(String behaviorName, int timeToComplete) {
for(int i = 0; i < this.behaviorList.length; i++) {
Behavior tempBehavior = this.behaviorList[i];
if( tempBehavior.getBehaviorName().equals(behaviorName)) {
tempBehavior.setTimeToComplete(timeToComplete);
}
}
}
// B
public void updateTimeTakenForBehavior(String behaviorName, int timeToComplete) {
for(int i = 0; i < this.behaviorList.length; i++) {
Behavior tempBehavior = this.behaviorList[i];
if( !tempBehavior.getBehaviorName().equals(behaviorName) ) {
tempBehavior.setTimeToComplete(timeToComplete);
}
}
}
// C
public void updateTimeTakenForBehavior(String behaviorName, int timeToComplete) {
for(int i = 0; i < this.behaviorList.LENGTH(); i++) {
Behavior tempBehavior = this.behaviorList[i];
if( tempBehavior.getBehaviorName().equals(behaviorName) ) {
tempBehavior.setTimeToComplete(timeToComplete);
}
}
}
// D
public void updateTimeTakenForBehavior(String behaviorName, int timeToComplete) {
for(int i = this.behaviorList.length; i < this.behaviorList.length; i++) {
Behavior tempBehavior = this.behaviorList[i];
if( tempBehavior.getBehaviorName().equals(behaviorName) ) {
tempBehavior.setTimeToComplete(timeToComplete);
}
}
}
}
Step by step
Solved in 2 steps