Creating a ChargedSuperhero This class is a child of Superhero and should inherit from it. An example
Question:
Creating a ChargedSuperhero
This class is a child of Superhero and should inherit from it. An example of this kind of superhero is Black Panther.
1.Create a class called ChargedSuperhero that has the following instance data:
a. charged: ChargedSuperheroes have a unique suit that allows them to charge energy and unleash a burst
of energy. Create a private variable that represents whether their suit is charged up or not named charged.
2.ChargedSuperheroshould have the following constructors:
a. Include a constructor that takes in name, health, damage, and charged in this order.
b. Include a default no-arguments constructor that creates a ChargedSuperhero with the following default
values:
•name is “Anonymous ChargedSuperhero",
•health is 30,
•damage is 10,
•charged 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.
3.ChargedSuperhero should have the following instance methods:
a.toStringmethod
•Must properly override Object’s toString() method.
•Should return:
SUPERHERO
Name: {name}
Health: {health}
Strength: {damage}
Suit Charged: {charged}
•Must utilize Superhero’s toString()method to optimize code.
b. equals()method
•Should override Object’s equals()method.
•Two ChargedSuperhero are equal if they have the same name, health, damage, and charged values.
•Must reuse code using Superhero’s equals() method.
c. attack(Superhero other)method:
•Overrides the Superhero 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 the suit of the ChargedSuperhero that called this method is charged, the ChargedSuperhero will deal damage equal to twice the amount of the value of damage(this ChargedSuperhero’s damage, not the other Superhero’s).
•If the suit of the ChargedSuperhero is NOT charged(charged equals false), deal damage equal to the value of damage(this ChargedSuperhero’s damage, not the other Superhero’s).
•The defending superhero’s health should not go below 0. If it does, set it back to 0.
Ethics Theory and Contemporary Issues
ISBN: 978-1305958678
9th edition
Authors: Barbara MacKinnon, Andrew Fiala