Question: Create 3 new Java subclasses and join all of the classes into a hierarchy. If the parent class has the same attributes as the sub
Create 3 new Java subclasses and join all of the classes into a hierarchy. If the parent class has the same attributes as the sub class then you can remove those attributes from the subclass. If the sub classes are shown on the same level, then they share a parent class.
| Player - Super Class | ||||
| Archer - Subclass | Barbarian - Subclass | Cleric - Subclass | Rogue - Subclass | Warlock - Subclass |
ADD 3 NEW SUBCLASSES WITH WITH 2 new attributes and one new functionality for each. Reference existing subclasses for example. Cleric: Stealth, int Armor, int getDamagePerArmoredAttack() - Double Method will return a double value. This value is a result of the math: (dexterity * 0.5 + armor * 0.8). You should not directly reference any attributes and should instead use the get methods for each attribute. Rogue: Focus, int Speed, int getDamagePerFocusAttack() - Double Method will return a double value. This value is a result of the math: (dexterity * 0.5 + focus * 0.8). You should not directly reference any attributes and should instead use the get methods for each attribute. Warlack: Magic, int Defense, int getDamagePerMagicAttack() - Double Method will return a double value. This value is a result of the math: (dexterity * 0.5 + magic * 0.8). You should not directly reference any attributes and should instead use the get methods for each attribute. EXISTNG SUPERCLASS: public class Player { private int Health; private int Intelligence; private int Dexterity; private int Strength; private int Stamina;
public Player() { }
public Player(int Health, int Intelligence, int Dexterity, int Strength, int Stamina) { this.Health = Health; this.Intelligence = Intelligence; this.Dexterity = Dexterity; this.Strength = Strength; this.Stamina = Stamina; }
public int getHealth() { return Health; }
public void setHealth(int Health) { this.Health = Math.max(Health, 0); }
public int getIntelligence() { return Intelligence; }
public void setIntelligence(int Intelligence) { this.Intelligence = Math.max(Intelligence, 0); }
public int getDexterity() { return Dexterity; }
public void setDexterity(int Dexterity) { this.Dexterity = Math.max(Dexterity, 0); }
public int getStrength() { return Strength; }
public void setStrength(int Strength) { this.Strength = Math.max(Strength, 0); }
public int getStamina() { return Stamina; }
public void setStamina(int Stamina) { this.Stamina = Math.max(Stamina, 0); }
@Override public String toString() { return "Player{" + "Health=" + Health + ", Intelligence=" + Intelligence + ", Dexterity=" + Dexterity + ", Strength=" + Strength + ", Stamina=" + Stamina + '}'; } }
EXISTING SUBCLASS ARCHER:
public class Archer { private int Health; private int Intelligence; private int Dexterity; private int Strength; private int Stamina;
public Archer() { }
public Archer(int Health, int Intelligence, int Dexterity, int Strength, int Stamina) { this.Health = Health; this.Intelligence = Intelligence; this.Dexterity = Dexterity; this.Strength = Strength; this.Stamina = Stamina; }
public int getHealth() { return Health; }
public void setHealth(int Health) { this.Health = Math.max(Health, 0); }
public int getIntelligence() { return Intelligence; }
public void setIntelligence(int Intelligence) { this.Intelligence = Math.max(Intelligence, 0); }
public int getDexterity() { return Dexterity; }
public void setDexterity(int Dexterity) { this.Dexterity = Math.max(Dexterity, 0); }
public int getStrength() { return Strength; }
public void setStrength(int Strength) { this.Strength = Math.max(Strength, 0); }
public int getStamina() { return Stamina; }
public void setStamina(int Stamina) { this.Stamina = Math.max(Stamina, 0); }
public double getDamagePerRangedAttack() { return getDexterity() * 0.5 + getIntelligence() * 0.8; }
public double getDamagePerMeleeAttack() { return getDexterity() * 0.5 + getStrength() * 0.8; }
@Override public String toString() { return "archer{" + "Health=" + Health + ", Intelligence=" + Intelligence + ", Dexterity=" + Dexterity + ", Strength=" + Strength + ", Stamina=" + Stamina + '}'; } }
EXISTING SUBLCASS BARBARIAN:
public class Barbarian { private int Health; private int Intelligence; private int Dexterity; private int Strength; private int Stamina;
public Barbarian() { }
public Barbarian(int Health, int Intelligence, int Dexterity, int Strength, int Stamina) { this.Health = Health; this.Intelligence = Intelligence; this.Dexterity = Dexterity; this.Strength = Strength; this.Stamina = Stamina; }
public int getHealth() { return Health; }
public void setHealth(int Health) { this.Health = Math.max(Health, 0); }
public int getIntelligence() { return Intelligence; }
public void setIntelligence(int Intelligence) { this.Intelligence = Math.max(Intelligence, 0); }
public int getDexterity() { return Dexterity; }
public void setDexterity(int Dexterity) { this.Dexterity = Math.max(Dexterity, 0); }
public int getStrength() { return Strength; }
public void setStrength(int Strength) { this.Strength = Math.max(Strength, 0); }
public int getStamina() { return Stamina; }
public void setStamina(int Stamina) { this.Stamina = Math.max(Stamina, 0); }
public double getDamageReducedPerBlock() { return getDexterity() * 0.5 + getIntelligence() * 0.8; }
public double getDamagePerMeleeAttack() { return getDexterity() * 0.5 + getStrength() * 0.8; }
@Override public String toString() { return "Barbarian{" + "Health=" + Health + ", Intelligence=" + Intelligence + ", Dexterity=" + Dexterity + ", Strength=" + Strength + ", Stamina=" + Stamina + '}'; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
