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

Assume we have a class called Person that has the instance variables name and ag

ID: 3770100 • Letter: A

Question

Assume we have a class called Person that has the instance variables name and age. It also has a default constructor, and has a constuctor that takes both of those values in as parameters. Fill in the rest of the class SuperVillain which inherits Person with the proper constructors:

a) A default constructor that sets the super power to a default value, initializes the array of henchmen(any size is fine) and also calls the Person's default constructor.

b)A parameterized constructor that takes in the super villains power, an array of Person for their henchmen, a name and age. Make sure they call the parents constructor.

Also Person has a method printInfo. Override this method calling the parent's printInfo along with printing the villain's power, and print out the info of every henchmen. You only have to write the constructos and the method denoted, you do not have to worry about error checking.

public class Super Villain extends Person{

String superPowers;

Person[] henchmen;

//Put your code here

Any help with this would be great. I have no idea what to do. Thanks!

Explanation / Answer

class Person{
   private String name;
   private int age;

   public Person(){

   }
   public Person(String name,int age){
       this.name = name;
       this.age = age;
   }  
   public void printInfo(){
       System.out.println(name + " is " + age + " years old.");
   }
}

public class SuperVillain extends Person{
   String superPowers;
   public SuperVillain(){
       superPowers = "";
       super();
   }
   public SuperVillain(String name,int age,String powers){
       superPowers = powers;
       super(name,age);
   }
   public void printInfo(){
       System.out.println(name + " is " + age + " years old and has "+ superPowers + " powers.");
   }

}