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

can you write the documentation of the code? public abstract class Monster exten

ID: 3838992 • Letter: C

Question

can you write the documentation of the code?

public abstract class Monster extends VBox implements Action {

private String name;

protected double health = 25;

protected Polygon triangle = new Polygon();

protected int diceSide;

protected int diceRound;

protected int[] holdSide;

  

Monster(String name) {

this.name = name;

}

void setDiceSide(int side) {

this.diceSide = side;

}

void setDiceRoll(int diceRound) {

   this.diceRound = diceRound;

   holdSide = new int[diceRound];

}

public int[] getResultRoll() {

   return holdSide;

}

public int[] rollDice() {

   int randNum;

   Random random1 = new Random();

   for (int i = 0; i < diceRound; i++) {

   holdSide[i] = random1.nextInt(diceSide) + 1;

}

   return holdSide;

}

  

public void setHealth(double newHealth) {

if (newHealth > 0) {

   health = newHealth;

} else {

   health = 0;

}

}

public double getHealth() {

   return health;

}

public String getName() {

   return name;

}

}

Explanation / Answer

The above can be understood line by line as follows. I have written every explanation in front of the line of the code in the form of comments. you can understand by reading through each line.

public abstract class Monster extends VBox implements Action { //create a class monster which inherits VBox // and implements the Action interface

private String name; //data variable representing name of the monster

protected double health = 25;    //data variable representing default health

protected Polygon triangle = new Polygon(); //reference variable of polygon along is created and instantiated.

protected int diceSide;   //data variable representing side of the dice

protected int diceRound;    //data variable representing number of rounds a dice is rolled

protected int[] holdSide;    //data variable in the form of int array holding the result of each round.

  

Monster(String name) { //parametrised constructor for initialising the name of monster.

this.name = name;

}

void setDiceSide(int side) { //setter method to set the number of side in dice.

this.diceSide = side;

}

void setDiceRoll(int diceRound) { //setter method to initialise the number of rounds

   this.diceRound = diceRound;

   holdSide = new int[diceRound]; //holdSide array is created according to the diceRound.

}

public int[] getResultRoll() { //getting the result of each roll in the form of interger array //by returning the holdSide which holds results for each occurance or roll.

   return holdSide;

}

public int[] rollDice() { //Method to roll the dice

   int randNum;

   Random random1 = new Random(); //random variable to assign random value on each roll

   for (int i = 0; i < diceRound; i++) {

   holdSide[i] = random1.nextInt(diceSide) + 1;//holdSide saves the result for each roll which is represented by //iteration of forloop here

}

   return holdSide; //return the holdSide array containing result of each roll

}

  

public void setHealth(double newHealth) { // setter method to set health

if (newHealth > 0) {

   health = newHealth;

} else {

   health = 0;

}

}

public double getHealth() { //getter method to get health

   return health;   

}

public String getName() { //getter method to get the name of monster

   return name;

}

}

Hope the above explanation helps. Using the comments above you can create your own custom documentation based upon the performa being provided by your instituition. You just need to copy paste the above things.

Cheers!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote