class Hero extends Being { protected int charisma; protected String name; protected Weapon holds; public Hero(int s, int d, int ch, String nm) { super(s,d); charisma=ch; name=nm; holds=null; } public Hero(int s, int d, int ch, String nm, Weapon w) { super(s,d); charisma=ch; name=nm; holds=w; } public String toString() { if(holds==null) return name; else return name+" armed with "+holds; } public int morale() { if(holds instanceof MagicWeapon) return (strength+defence+charisma)*2/3; else return (strength+defence+charisma)/3; } public void attack(Being b) { if(holds!=null) b.hit(strength,holds.getPower()); } public void attack(Being b, Weapon w) { b.hit(strength,w.getPower()); } public void pickUp(Weapon w) { holds=w; } public boolean mightier(Being b) { if(b instanceof Hero) { Hero h = (Hero) b; if(h.holds!=null) if(holds!=null) return (strength+holds.getPower()>h.strength+h.holds.getPower()); else return (strength>h.strength+h.holds.getPower()); else if(holds!=null) return (strength+holds.getPower()>h.strength); else return (strength>h.strength); } else return strength>b.strength; } }