I am trying to create a Monster class for a project. My attributes are healthPoints, damage, description, and type (where type is an enum). Currently, it has a default constructor, a full constructor, and a constructor which accepts only the enum monsterType.
My issue is here: In the driver, using the random class, a random monsterType is chosen, and a new Monster is created. However, healthPoints, damage, and description all print to the screen as 0 or null.
I believe the issue is in my setters for each of those attributes. I have a switch statement in each setter, to set a certain number of healthPoints, etc, based on what type of monster is randomly generated. Here is my healthPoints setter as an example:
public void setHealthPoints(int healthPoints)
{
switch(type)
{
case DROW:
this.healthPoints = 30;
break;
case LICH:
this.healthPoints = 40;
break;
case ORC:
this.healthPoints = 20;
break;
case OWLBEAR:
this.healthPoints = 20;
break;
case RUST_MONSTER:
this.healthPoints = 10;
break;
}
this.healthPoints = healthPoints;
}
I'm not sure how much help I can get without showing the full code, but any suggestions as to what I could do to get this to work would be much appreciated! Thank in advance!
1 answer