How do I set up attributes in Java with "range values? "
for example. GameField is my class.
GameField will have the following attributes:
public class GameField { private int hitPoints; private int strength; /* Modify hitPoints and strength only if they are in valid range. so, every time you want to modify one of these attributes, make sure you use these setter methods below. don't modify them directly */ public void setHitPoints(int hitPoints) { if (hitPoints >= 0 && hitPoints <= 125) this.hitPoints = hitPoints; } public void setStrength(int strength) { if (strength >= 0 && strength <= 20) this.strength = strength; } }
Get Answers For Free
Most questions answered within 1 hours.