Using Java Do whatever you understand i will thumbs up Bellow is animal class(actor class is not needed). Create a test class for animal, there will be a skeleton code underneath animal class to help u create this test class. public class Animal extends Actor { //~ Fields ................................................................ private int age; private int speed; //~ Constructor ........................................................... // ---------------------------------------------------------- / * Creates a new Animal object. * * @param speed The speed at which this animal moves (number * of cells per turn). */ public Animal(int speed) { age = 0; this.speed = speed; } //~ Methods ............................................................... // ---------------------------------------------------------- / * Get the age of this animal, in number of turns. * * @return This animal's age. */ public double getAge() { return age; } // ---------------------------------------------------------- / * Get the speed of this animal, in number of cells moved per * turn. * * @return This animal's speed. */ public int getSpeed() { return speed; } // ---------------------------------------------------------- / * Pick a new direction for this animal. The implementation * in this class turns a random amount between +45 and -45 * degrees. Subclasses can override this behavior to use a * different turning strategy. */ public void turn() { int angle = Random.generator().nextInt(90) - 45; this.turn(angle); } // ---------------------------------------------------------- /** * Execute this animal's behavior for one turn. */ public void act() { age++; this.turn(); this.move(getSpeed()); } } ----------------------------------------------------------------------------------------- Skeloton code below public class AnimalTest extends TestCase { //~ Fields ................................................................ //~ Constructor ........................................................... // ---------------------------------------------------------- / * Creates a new AnimalTest test object. */ public AnimalTest() { // The constructor is usually empty in unit tests, since it runs // once for the whole class, not once for each test method. // Per-test initialization should be placed in setUp() instead. } //~ Methods ............................................................... // ---------------------------------------------------------- / * Sets up the test fixture. * Called before every test case method. / public void setUp() { /# Insert your own setup code here / } // ---------------------------------------------------------- /# Insert your own test methods here */ }
Using Java
Do whatever you understand i will thumbs up
Bellow is animal class(actor class is not needed). Create a test class for animal, there will be a skeleton code underneath animal class to help u create this test class.
public class Animal extends Actor
{
//~ Fields ................................................................
private int age;
private int speed;
//~ Constructor ...........................................................
// ----------------------------------------------------------
/
* Creates a new Animal object.
*
* @param speed The speed at which this animal moves (number
* of cells per turn).
*/
public Animal(int speed)
{
age = 0;
this.speed = speed;
}
//~ Methods ...............................................................
// ----------------------------------------------------------
/
* Get the age of this animal, in number of turns.
*
* @return This animal's age.
*/
public double getAge()
{
return age;
}
// ----------------------------------------------------------
/
* Get the speed of this animal, in number of cells moved per
* turn.
*
* @return This animal's speed.
*/
public int getSpeed()
{
return speed;
}
// ----------------------------------------------------------
/
* Pick a new direction for this animal. The implementation
* in this class turns a random amount between +45 and -45
* degrees. Subclasses can override this behavior to use a
* different turning strategy.
*/
public void turn()
{
int angle = Random.generator().nextInt(90) - 45;
this.turn(angle);
}
// ----------------------------------------------------------
/**
* Execute this animal's behavior for one turn.
*/
public void act()
{
age++;
this.turn();
this.move(getSpeed());
}
}
-----------------------------------------------------------------------------------------
Skeloton code below
public class AnimalTest extends TestCase
{
//~ Fields ................................................................
//~ Constructor ...........................................................
// ----------------------------------------------------------
/
* Creates a new AnimalTest test object.
*/
public AnimalTest()
{
// The constructor is usually empty in unit tests, since it runs
// once for the whole class, not once for each test method.
// Per-test initialization should be placed in setUp() instead.
}
//~ Methods ...............................................................
// ----------------------------------------------------------
/
* Sets up the test fixture.
* Called before every test case method.
/
public void setUp()
{
/# Insert your own setup code here /
}
// ----------------------------------------------------------
/# Insert your own test methods here */
}
Step by step
Solved in 2 steps with 1 images