Player Class

Follow these steps in order to develop the Player Class

  1. Create a class called Player

  2. The game involves Crewmates and Imposters, no players can exist -- make it abstract!

  3. The Player has three states, a String name, boolean isAlive, boolean isImposter

  4. The player has one constructor that takes 3 parameters. These match the states of the class.

    1. In the constructor set the states equal to the parameters

  5. Write three accessors, one for each state

    1. getName()

    2. getIsAlive()

    3. getIsImposter()

  6. Write a mutator to change isAlive to true or false depending on the needs later on.

    1. setIsAlive(boolean b)

  7. Write a method called void move() that checks if the player is alive and if so prints out "Name is moving suspiciously";

  8. 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();

}