Answer to Question #210865 in Java | JSP | JSF for Ronnie

Question #210865

Question: Use your own theme to make your own class design and implementation unique, giving the character unique attributes and actions.

 Implement a main game character object oriented class type to simulate what is common to all characters in your game

A class data field (variable) (data member) to represent the name/identifier of the character/ make sure each character can carry an item


1
Expert's answer
2021-06-27T14:11:34-0400
public abstract class Hero {
    private String name;
    private Item item;

    public Hero(String name, Item item) {
        this.name = name;
        this.item = item;
    }

    public abstract String battleRoar();

    public String getName() {
        return name;
    }

    public int attack(){
        return item.getStrength();
    }
}


public class Gandalf extends Hero {
    private int magicPower;

    public Gendalf(String name, Item item, int magicPower) {
        super(name, item);
        this.magicPower = magicPower;
    }

    @Override
    public String battleRoar() {
        return "You shall not pass.";
    }

    @Override
    public int attack() {
        return super.attack() + magicPower;
    }
}


public class Frodo extends Hero{
    public Frodo(String name, Item item){
        super(name, item);
    }

    @Override
    public String battleRoar() {
        return "For the Fellowship!";
    }
}


public class Item {
    private String name;
    private int strength;

    public Item(String name, int strength) {
        this.name = name;
        this.strength = strength;
    }

    public String getName() {
        return name;
    }

    public int getStrength() {
        return strength;
    }
}

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