/**
* Flubbers are Doodads with Locomotion and Talking capabilities
*
* @author Loren Segal
* @version 1.0
*/
public class Flubber extends Doodad implements Locomote, Talker
{
// Constants for the Locomote interface
private static final String MOVE_TYPE = "Walk";
private static final int MIN_DISTANCE = 5;
// Constants for the Talker interface
private static final String SAY_HI = "Hi";
private static final String SAY_BYE = "Bye Bye";
// Class variables
private int distance;
//=== Constructors ===//
/**
* Create a new Flubber with a name and move distance.
* If the distance is smaller than MIN_DISTANCE (currently 5)
* then the minimum age will be Doodad default. Otherwise, the
* minimum age will be unrestricted.
*
* @param name Name of the Flubber
* @param newDistance How far the Flubber will move
*/
public Flubber(String name, int newDistance)
{
super(name);
if (newDistance >= MIN_DISTANCE)
{
this.setMinAge(-1);
}
setDistance(newDistance);
}
/**
* Create a new Flubber with a name, move distance and minimum age.
* If an object is instantiated with this constructor, there will be no
* distance check to make the minimum age unrestrcited.
*
* @param name Name of the Flubber
* @param newDistance How far the Flubber will move
* @param minAge The minimum age limit
*/
public Flubber(String name, int newDistance, int minAge)
{
super(name, minAge);
setDistance(newDistance);
}
//=== End constructors ===//
/**
* Sets the move distance for the Flubber
*/
public void setDistance(int newDistance)
{
distance = newDistance;
}
//=== Locomote Interface ===//
/**
* Part of the Locomote interface;
* returns the move type of the Flubber.
*
* @return the move style for the Flubber, currently: Walk
*/
public String style()
{
return MOVE_TYPE;
}
/**
* Part of the Locomote interface;
* returns the move distance of the Flubber.
*
* @return the move distance of the Flubber.
*/
public int howFar()
{
return distance;
}
//=== End Locomote Interface ===//
//=== Talker Interface ===//
/**
* Makes the Flubber say hi via the Talker interface
*
* @return Currently returns "Hi"
*/
public String sayHi()
{
return SAY_HI;
}
/**
* Makes the Flubber say bye via the Talker interface
*
* @return Currently returns "Bye Bye"
*/
public String sayBye()
{
return SAY_BYE;
}
//=== End Talker Interface ===//
public String toString()
{
String strMinAge;
if (this.getMinAge() == -1)
{
strMinAge = "unrestricted";
}
else
{
strMinAge = this.getMinAge() + " and above";
}
return super.toString() + "Age: " + strMinAge + "\n";
}
} Powered by
GeSHi Syntax Highlighting software.
Author of all (other) material unless otherwise specified:
Loren Segal. Copyright 2005.