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: 3893747 • 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 o Create a method called eatPeasant that increases peasantsEaten by one Create a method called getPeasantsEaten that returns peasantsEaten. Override isFriendly to return false

Explanation / Answer

//Dragon.java

package dragon;

public abstract class Dragon {

private int breathDamage;

private String name;

public Dragon() {

name="GenericDragon";

breathDamage=10;

}

public Dragon(int breathDamage, String name) {

this.breathDamage = breathDamage;

this.name = name;

}

public int getBreathDamage() {

return breathDamage;

}

public String getName() {

return name;

}

public abstract boolean isFriendly();

public static void main(String[] args) {

}

}

//ChromaicDragon.java

import dragon.Dragon;

public class ChromaicDragon extends Dragon{

private int peasentEaten;

public ChromaicDragon(int damage, String name) {

super(damage, name);

this.peasentEaten = 0;

}

@Override

public boolean isFriendly() {

return false;

}

public void eatPeasent() {

peasentEaten++;

}

public int getPeasentsEaten() {

return peasentEaten;

}

}

//MetallicDragon .java

import dragon.Dragon;

public class MetallicDragon extends Dragon{

private int peasentSaved;

public MetallicDragon(int damage, String name) {

super(damage, name);

this.peasentSaved = 0;

}

public void savePeasent() {

peasentSaved++;

}

public int getPeasentSaved() {

return peasentSaved;

}

@Override

public 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