Question
This class is a child of Superhero and should inherit from it. An example of this kind of superhero is Captain Marvel. 4.Create a class
This class is a child of Superhero and should inherit from it. An example of this kind of superhero is Captain Marvel.
4.Create a class called FlyingSuperhero that has the following instance data:
a. flying: a FlyingSuperhero has a unique suit that allows them to fly. Create a private variable that represents whether they are in flight or not called flying
5.FlyingSuperhero should have the following constructors:
a. Include a constructor that takes in name, health, damage, and flying in this order.
b .Include a default no-arguments constructor that creates a FlyingSuperhero with the following default values:
•name is “Anonymous FlyingSuperhero",
•health is 40,
•damage is 7,
•flying is false.
•Use constructor chaining to call the other constructor in this class with default values.
c .Ensure that you are calling the parent constructor appropriately.
6.FlyingSuperheroshould have the following instance methods:
a. to string method
•Must properly override Object’s toString() method.
•Should return:
SUPERHERO
Name: {name}
Health: {health}
Strength: {damage}
Flying: {flying}
•Must utilize Superhero’s toString()method to optimize code.
b. equals()method
•Should override Object’s equals()method.
•Two FlyingSuperhero are equal if they have the same name, health, damage, and flying values.
•Must reuse code using Superhero’s equals()method.
c. attack(Superhero other)method:
•Overrides the Superhero’s attack method.
•Deals damage to the superhero that is taken in as a parameter.
•Only deals damage if the attacking superhero has more than 0 health.
•If FlyingSuperhero is flying, there is a 50% chance that FlyingSuperhero will deal damage equal to 3x the amount of the value of damage. If chance fails, deal damage equal to the value of damage(in both cases, use this FlyingSuperhero’s damage, not the other Superhero’s). o
HINT: Use Random or Math methods to calculate this chance.(HINT: there is a nextBoolean method in the Random class but you can also use numbers)
•If FlyingSuperhero is not flying, deal damage equal to the value of damage
.•The defending superhero’s health should not go below 0. If it does, set it back to 0.
Step by Step Solution
3.40 Rating (153 Votes )
There are 3 Steps involved in it
Step: 1
Explanation Superherojava public class Superhero INSTANCE VARIABLES private String name private int health private int damage CONSTRUCTOR WITH 3 ARGUM...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started