๐ปAdd a main() method to Melee.
Main methods always have the same declaration:
publicstaticvoidmain(String[]args)
public: this means it can be accessed outside of this class
static: this means this method belongs to the whole class, not just one particular object
void: this means it will not return anything
String[] args: this means that this method can accept parameters from the user
๐ปCreate 4 Superhuman objects in the main() method.
Since they are in the same model, Melee can access the Superhuman class. However, it can only access attributes/methods that have the public access modifier.
Because the main() method is static, we can run it even before we have created a constructor for Melee.
Be sure to test our your main() method to make sure it’s working before moving on!
๐ปAdd the following attributes to the Melee class.
villains: an array of size 20, that holds Superhuman objects
heroes: an array of size 20, that holds Superhuman objects
villainPoints: int
heroPoints: int
How to use arrays:
int[]myArray;// declare a new array variable
myArray=newint[20];//create an new array of integers and save it in your variable
myArray[0]= 8;//adds the integer 8 at index 0
๐ปAdd a constructor to Melee.
The constructor is the method that runs when a new object is created. Remember, the constructor must have the same name as the class. Take a look at the constructor from the other classes in this lab for inspiration.
The Melee constructor should takes no parameters. It creates arrays for villains and heroes. It sets bothvillainPoints and heroPoints to zero.
Constructors automatically return an object of their class, so you don’t need any return statement
We want to make it so that two of the superhumans can fight. However, first we need to know how what power the superhuman has, and how strong they are:
๐ปAdd three attributes: strength, powers, and isVillain to the Superhuman class.
strength: an int that stores how powerful they are power: a String that stores the name of their power isVillain: a boolean that stores whether the super is a villain or not.
๐ปFor each new attribute, create a setter and a getter (aka mutator and accessor).
๐ปUpdate the Superhuman constructor to include parameters for the new attributes. You will also need to update any Superhuman objects that you create to include these new attributes.