Player Class
Follow these steps in order to develop the Player Class
Create a class called Player
The game involves Crewmates and Imposters, no players can exist -- make it abstract!
The Player has three states, a String name, boolean isAlive, boolean isImposter
The player has one constructor that takes 3 parameters. These match the states of the class.
In the constructor set the states equal to the parameters
Write three accessors, one for each state
getName()
getIsAlive()
getIsImposter()
Write a mutator to change isAlive to true or false depending on the needs later on.
setIsAlive(boolean b)
Write a method called void move() that checks if the player is alive and if so prints out "Name is moving suspiciously";
Write a void method called doTask(), this method will be implemented in our other classes, so we will make this abstract.
Click to Reveal Mr. Wile's Code ***WARNING ONLY IF NEEDED***
/*
* @Jeffrey Wile
* 12/1/2020
*/
public abstract class Player {
private String name;
private boolean isAlive;
private boolean isImposter;
public Player(String n, boolean alive, boolean imposter) {
name = n;
isAlive = alive;
isImposter = imposter;
}
public String getName() {
return name;
}
public boolean getIsAlive() {
return isAlive;
}
public boolean getIsImposter() {
return isImposter;
}
public void setIsAlive(boolean b) {
isAlive = b;
}
public void move() {
if(isAlive) {
System.out.println(name + " is moving");
}
}
public abstract void doTask();
}