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
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.");
}
}
Comments
Leave a comment