Answer to Question #213637 in Java | JSP | JSF for Karon Aldrich

Question #213637

1)  Implement an object oriented subclass of Character, to simulate a specific kind of character in your game. For example, a ’warrior’ class. A warrior is a character, but a character is not necessarily a warrior.

2)  Include one unique data field for an attribute of the specific character that is not inherited or defined in Character class

3) Implement a method which overrides the Character attack method to make your subclass simulate a more specific kind of attack that relates to its type, with informative printouts


1
Expert's answer
2021-07-04T17:11:31-0400
public class Character {
    private String name;
    private int damage;

    public Character(String name, int damage) {
        this.name = name;
        this.damage = damage;
    }

    public void attack() {
        System.out.println(name + " dealt " + damage + " damage.");
    }

    public String getName() {
        return name;
    }

    public int getDamage() {
        return damage;
    }
}


public class Warrior extends Character {
    private int defense;

    public Warrior(String name, int damage, int defense) {
        super(name, damage);
        this.defense = defense;
    }

    @Override
    public void attack() {
        System.out.println(getName() + " blocked " + defense + " damage and dealt " + getDamage() + " damage.");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS