// Note: comments about which requirements are met will be on top of the line of code that meets the requirement
// This is a new class created in the Spring Semester, so #1-18 will not be included in the comments for this class.
public class GameCharacter implements Position { // #22 - implementing student-designed interface
// instance variables
private double position;
private String name;
public GameCharacter() { // zero arg
position = 0.0;
name = "Enemy";
}
public GameCharacter(double position, String name) { // multi-arg
this.position = position;
this.name = name;
}
// #20 - using method from different class/interface
public double getPosition() { // getter for position instance var
return position;
}
// #20 - using method from different class/interface
public void setPosition() { // setter for position instance var
this.position = position;
}
public String getName() { // getter for name instance var
return name;
}
public void setName(String name) { // setter for name instance var
this.name = name;
}
// #20 - using method from different class/interface
public String getDirection() { // returns direction based on position
String direction = "";
if (position > 0.0) {
direction = "Left";
} else if (position < 0.0) {
direction = "Right";
} else if (position == 0.0) {
direction = "Middle";
}
return direction;
}
public String toString() { // toString
return "This character's name is " + name + ".\nThis character's position is " + position + ".\nThis character's direction is " + this.getDirection() + ".";
}
} // end class