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

Please do the following question using Java. Also please separate these into the

ID: 3852799 • Letter: P

Question

Please do the following question using Java. Also please separate these into the separate classes (use Inheritance [extends...]): Vampire.java, Zombie.java, GeneralZod.java and finally MonsterTester.java. You are also given the following abstract Monster.java class and a Hero.java class:

Monster.java

public abstract class Monster {

   private int health;
  
   /**
   * Single-argument constructor
   * @param health The initial health of the monster.
   */
   public Monster(int health) {
       this.health = health;
   }
  
   /**
   * Determine if the monster is dead (health <= 0)
   * @return true if monster is dead, otherwise false
   */
   public boolean isDead() { return health <= 0; }
  
   /**
   * Reduce the Monster's health.
   * @param damage amount of health reduction
   */
   public void takeDamage(int damage) { health -= damage; }
  
   /**
   * Monster's current health
   * @return current health value.
   */
   public int getHealth() {return health; }
  
   /**
   * Abstract method to be implemented by subclasses
   * @return the amount of damage dealt to the opponent.
   */
   public abstract int dealDamage();
  
   /**
   * Abstract method to be implemented by subclasses
   * @return Special affliction to be kept track of by the opponent.
   */
   public abstract String afflict();   

}

Hero.java

public class Hero {
  
   private final String name;
   private int health;
  
   /**
   * Single argument constructor.
   * @param name name of the hero.
   */
   public Hero(String name){
      
       this.name = name;
      
       //arbitrary settings. A more argumented constructor could help here.
       health = 100;
   }
  
   /**
   * Damage inflicted by an opponent.
   * @param damage amount of health to be reduced.
   */
   public void takeDamage(int damage){
       health -= damage;
   }
  
   /**
   * Amount of damage to inflict on an opponent.
   * @return damage inflicted on opponent.
   */
   public int dealDamage(){
       return (int)((Math.random() * 10) + 5);
   }
  
   /**
   * Amount of health
   * @return health
   */
   public int getHealth(){ return health; }
  
   /**
   * Name of hero
   * @return name
   */
   public String getName() { return name; }
  
  
   /**
   * Determine if Hero is dead.
   * @return true if dead, otherwise false.
   */
   public boolean isDead(){return health <= 0; }
  
   /**
   * Standard toString() method.
   */
   public String toString(){
       return "Hero[" + name + ", " + health + "]";
   }

}

Given those, you have the following questions:

NOTE:****VERY IMPORTANT****Please use the dealDamage(); method from Hero.java, and as well as toStrings();. Additionally the random health of each monster should be in its own class. For example, the health of the Zombie, should be in Zombie.java, the health of the Vampire should be in Vampire.java and so on. This is done so that when you create an array of object like: monsters[i] = new Vampire(); it should automatically have the Vampire's health from its class. Also edit the default constructor for Hero and finally use lots of display lines and spaces in the tester for final output. This is the tester:

****NOTE VERY IMPORTANT FOR TESTER***. IN THE TESTER MAKE SURE THAT WHEN CREATING RANDOM 5 MONSTERS, ONLY ONE GENERALZOD IS CREATED

AND HE APPEARS AS THE LAST MONSTER CREATED!!!!.

2. A) (Vampire.java, Zombie.java, GeneralZod.java, MonterTester,java 25 marks) (15 marks) Consider the abstract Monster class that is given to you in the project file. This class defines the essential characteristics of Monsters that might be used in a game. Your jobs is to create three specific Monster classes-as described below - and to follow the standard rules of inheritance in doing so (override methods that need to be overridden, implement methods that need to be implemented, do NOT override or implement methods that are adequately implemented in the superclass, etc., etc.) Vampire: A vampire starts off with between 8 and 12 health. They aren't very healthy and they do only between 6 and 9 damage per turn. Zombie: Zombies are a bit tougher so they start off with health between 11 and 16. They also do a bit more damage - between 8 and 14 per turn. General Zod: General Zod is kind of a bad guy- he means well, but still... Thanks to the Earth's yellow sun his starting health is between 25 and 30 and he does a damaging 12 to 20 per turn. Make sure that each Monster has a toString) method for easy display.

Explanation / Answer

Given below is implementation for described problem. Sample execution output is also provided for reference. As in the above specification requirement for afflict interface is not clearly provided a static string is returned by Vampire, Zombie and GeneralZod classes.

File: Monster.java

File: Vampire.java

File: Zombie.java

File: GeneralZod.java

File: Hero.java

File: MonsterTester.java

Sample Execution Output:

Hero[yoda, 100] attacks Monster 1 (Zombie[12]): damage is 12
Hero[yoda, 100] attacks Monster 2 (Zombie[12]): damage is 13
Hero[yoda, 100] attacks Monster 3 (Vampire[11]): damage is 5
Monster 3 (Vampire[6]) attacks Hero[yoda, 100]: damage is 6
Hero[yoda, 94] attacks Monster 4 (Vampire[9]): damage is 11
Hero[yoda, 94] attacks Monster 5 (GeneralZod[25]): damage is 10
Monster 5 (GeneralZod[15]) attacks Hero[yoda, 94]: damage is 18
Our hero (Hero[yoda, 76]) deals with below afflictions:
   Monster 3 (Vampire[6]): This is Vampire's affliction.
   Monster 5 (GeneralZod[15]): This is General Zod's affliction.
Hero[yoda, 76] attacks Monster 3 (Vampire[6]): damage is 10
Hero[yoda, 76] attacks Monster 5 (GeneralZod[15]): damage is 8
Monster 5 (GeneralZod[7]) attacks Hero[yoda, 76]: damage is 13
Our hero (Hero[yoda, 63]) deals with below afflictions:
   Monster 5 (GeneralZod[7]): This is General Zod's affliction.
Hero[yoda, 63] attacks Monster 5 (GeneralZod[7]): damage is 7
Our hero (Hero[yoda, 63]) wins!