Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a class Critter which represents an animal. Critter class will be

ID: 3809501 • Letter: Y

Question

You are given a class Critter which represents an animal. Critter class will be the superclass of a set of subclasses classes. A Critter has a weight and a position on a number line. The constructor initializes the position to 0 and sets the weight from the parameter. Critter has an ArrayList of Strings to keep a log of its activities. It has other methods which you can view below:

You are to implement the following subclasses of Critter

ImpatientCritter: A ImpatientCritter is always in a hurry If you tell an ImpatientCritter to move 5, it will actually move 10 steps. You will override the move method.

LethargicCritter: A LethargicCritter only has two activities: eat and sleep. When asked to move, it will either eat or sleep. A LethargicCritter is created hungry so the first time its move method is called, the LethargicCritter should eat. (and add the word "eat" to the history. The next time the move method is called, the LethargicCritter will sleep (and add the word "sleep" to the history). It will continue to alternate activities in this manner.

MulishCritter: A MulishCritter is very stubborn. It only moves every third time you tell it it move. You will override the move method. If you call the MulishCritter's move method 4 times, it will move the requested amount, not move, not move, move the requested amount. (The % operator is handy here)

Provide Javadoc. You can use @Override for overridden methods

---------------------------------------------------------------------------------------------------------------------

Use the following .java files:

Critter.java

CritterRunner.java

CritterTester.java

Class Critter lang, biset Critter pallie elas critter extends java. long. objeat A simulated c tte Constructor Summary Constructs a critter at position 0 with blank history. Method Summary laag, Adds to the history of this critter. Array Keutistory Gets the history of this critter. int Retrosition() Gets the position of this critter. ble Moves this critter. Methods inherited from class fyA

Explanation / Answer

PROGRAM CODE:

ImpatientCritter.java

package critter;

/**

* A simulated impatient critter.

*/

public class ImpatientCritter extends Critter{

  

   /**

   Constructs a critter at position 0 with blank history.

   */

   public ImpatientCritter(double theWeight) {

       super(theWeight);

   }

   /**

   Moves this critter twice the number of steps.

@param steps the number of steps by which to move.

   */

   @Override

   public void move(int steps) {

       super.move(steps*2);

   }

}

LethargicCritter.java

package critter;

/**

* A simulated lethargic critter.

*/

public class LethargicCritter extends Critter{

   // 0 - eat

   // 1 - sleep

   private int flip;

  

   /**

   Constructs a critter at position 0 with blank history.

*/

   public LethargicCritter(double theWeight) {

       super(theWeight);

       flip = 0;

   }

  

   /**

   This critter performs only eat or sleep. the activity is alternative each time

   @param steps the number of steps by which to move.

*/

   @Override

   public void move(int steps) {

       if(flip == 0)

       {

           addHistory("eat");

           flip = 1;

       }

       else

       {

           addHistory("sleep");

           flip = 0;

       }

   }

}

MulishCritter.java

package critter;

/**

* A simulated mulish critter.

*/

public class MulishCritter extends Critter{

   private int moveCounts;

  

   /**

   Constructs a critter at position 0 with blank history.

   */

   public MulishCritter(double theWeight) {

       super(theWeight);

       moveCounts = 0;

   }

   /**

   Moves this critter only after third time.

   @param steps the number of steps by which to move.

   */

   @Override

   public void move(int steps) {

      

       if(moveCounts%3==0 || moveCounts == 0)

           super.move(steps);

       moveCounts++;

   }

}

OUTPUT:

[move to 20, move to 14]

Expected: [move to 20, move to 14]

14

Expected: 14

[eat, sleep, eat, sleep, eat]

Expected: [eat, sleep, eat, sleep, eat]

0

Expected: 0

[move to 2, move to 5]

Expected: [move to 2, move to 5]

5

Expected: 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote