Answered step by step
Verified Expert Solution
Question
1 Approved Answer
. . 4 . A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it actually moves by
A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it actually moves by n steps. Implement a FastCritter subclass of Critter whose move method behaves as described. FastCritter.java Critter.java import java.util.ArrayList; A simulated critter. public class Critter private int position; private ArrayList history; Constructs a critter at position with blank history. public Critter position ; history new ArrayList; Gets the history of this critter. @return the history public ArrayList getHistory return history; Adds to the history of this critter. @param newValue the desired state Adds to the history of this critter. @param newValue the desired state public void addHistory String event history.addevent; Gets the position of this critter. @return the position public int getPosition return position; Moves this critter. @param steps the number of steps by which to move. public void moveint steps position position steps; addHistorymove to position; The action of this critter in one step of the simulation. public void act FastCritterTester.java public class FastCritterTester public static void mainString args Critter speedy new FastCritter; speedy.move; System.out.printlnspeedygetHistory ; System.out.printlnExpected: move to ; speedy.move; System.out.printlnspeedygetHistory; System.out.printlnExpected: move to move to ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started