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):

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

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);

            }

        }

    }

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT