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

5. A game app involves players modeled as creatures by the Creature class: publi

ID: 3686748 • Letter: 5

Question

5. A game app involves players modeled as creatures by the Creature class:

public class Creature{
    private String name;
    private int lifeLevel;

  public Creature(String name, int level){
    this.name=name;
    lifeLevel=level;
  }
  public String getName(){
    return name;
  }
  public int getLifeLevel(){
    return lifeLevel;
  }
  public void changeLifeLevel(int amt){
     lifeLevel+=amt;
  }
  public String toString(){
    return("Name: " + name + ", life level: " + lifeLevel);
  }
}


Create a sub class of the Creature class called the Dragon class. A dragon has the following attributes:
flight range, the distance it can fly in kilometers, and flame strength, how much ability it has to breath fire.
The flight range is a decimal value, and flame strength is a whole number in the range of 0 to 100 inclusive.

Declare the variables flightRange and flameStrength.

Both of these attribute values are initialized in the dragon's constructor.

Write the getFlightRange and getFlameStrength methods (no "set" methods) for returning the flight range and flame strength respectively.

Override the Creature class toString method so that it returns this String:
"Name: Smaug, life level: 100, range: 150.0, flame: 75"
for a dragon named Smaug with life level 100, flight range 150.0 and flame strength of 75.
Your Dragon class toString method MUST use a call to the Creature class's toString method.

Answer:

Explanation / Answer

public class Dragon extends Creature

{

private long flightRange,

private int flameStrength;

public long getflightRange()

{

return flightRange;

}

public int getflameStrength()

{

return flamestrength;

}

public String toString(){
    system.out.println ("Name: "
Smaug ", life level: " 100" , Range: "150.0", flame: "75");

}

}

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