Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to define an abstract class called Dragon, because everything is better

ID: 3908025 • Letter: Y

Question

You are to define an abstract class called Dragon, because everything is better with dragons. The class must meet the following specifications: The class should have an integer field to store the amount of damage the dragon's breath attack does (called breathDamage) and a String to hold the dragon's name (called name). You must choose the appropriate access level for your fields. You must provide two constructors for the class. The first is a parameterized constructor that takes in the breathDamage and name and initializes them. The second is a no parameter constructor that calls the parameterized constructor with name as Generic Dragon and breathDamage of 10. You will use the this keyword to call the other constructor Create a method called getName that returns the dragon's name. Create a method called getBreathDamage that returns the dragon's breath damage. Create an abstract method called isFriendly that takes no parameters and returns a boolean You will now create two derived classes from the Dragon class. The first is called ChromaticDragon. The class must meet the following specifications: The class should have an integer field to store the number of peasants eaten (called peasantsEaten). You must choose the appropriate access level for your fields. You must provide a single constructor for the class. This is a parameterized constructor that takes in the breathDamage and name and passes them to the super constructor. It then sets peasantsEaten to 0 Create a method called eatPeasant that increases peasantsEaten by one. Create a method called getPeasantsEaten that returns peasantsEaten. Override isFriendly to return false. The second is called MetallicDragon. The class must meet the following specifications:

Explanation / Answer

//abstract Dragon class abstract class Dragon{ //data members private int breathDamage; private String name; //Default constructor public Dragon() { name = "GenericDragon"; breathDamage = 10; } //argumented constructor public Dragon(int breathDamage, String name) { this.breathDamage = breathDamage; this.name = name; } //Getters public int getBreathDamage() { return breathDamage; } public String getName() { return name; } //abstract method abstract boolean isFriendly(); } //ChromaticDragon class class ChromaticDragon extends Dragon{ //data member private int peasantsEaten; //Argumented constructor ChromaticDragon(int damage, String name){ super(damage,name); peasantsEaten = 0; } public int getPeasantsEaten() { return peasantsEaten; } @Override boolean isFriendly() { return false; } public void eatPeasant(){ peasantsEaten++; } } //Metallic Dragon class class MetallicDragaon extends Dragon{ //Data member private int peasantsSaved; //Argumented constructor MetallicDragaon(int damage, String name){ super(damage,name); peasantsSaved = 0; } public void savePeasant(){ peasantsSaved++; } public int getPeasantsSaved(){ return peasantsSaved; } @Override boolean isFriendly() { return true; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote