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

THIS IS JAVA LANGUAGE, i think it\'s only override the sethp method everything s

ID: 3849465 • Letter: T

Question

THIS IS JAVA LANGUAGE, i think it's only override the sethp method everything sub class i would write its own method

This project requires you to create a class for the Dungeon Character. This will be the base class.

The members include:

String name

int HP

int dmax, dmin // minimum and maximum damage

double chanceInt // chance to hit

int attackSpeed // speed of attack

The methods include:

a constructor that takes in the characters name, max hps, max damage, and min damage as well as the attack speed and chance to hit. you will assign these values to the class members.

isAllive() returns true if the character is alive

getName() returns character name

setHP(int HPin) sets character's hp

attack() performs attack for character. will be modified by later classes that inherit from dungeon character

successfulAction(double chance) returns true if the character successfully hits

getNumTurns(int mAttackSpeed) returns 1 if characters attack speed is less than opponents otherwise integer math to divide characters attack speed by opponents

getHP() return characters current HP

getMaxHP() return characters max HP

This class will start out as public but eventually will become abstract.

First, change the dungeon character class to abstract. Once you do you will add an abstract method called showInfo(). This method will return void.

Second create two classes that inherit from the dungeon class. The first is the hero class.

This class will contain a member to store the chanceToBlock in a double.

The constructor will take in the name, max hp's, max and min damage, chance to hit, chance to block, as well as attack speed. Everything except the chance to block will be passed to the super class.

You will override the setHP(int hpIn) method to include a chance to block. You will take a random int and compare it to the chance to block. If the random number is lower than the chance to block you have successfully blocked the attack and will pass zero to the super setHP(hpOut). Otherwise you will multiply the hpIn by -1 and pass it on to the super setHP(hpOut).

The second class is the monster class.

This class will have a member to store the chance to heal, as well as members to store max heal and min heal.

The constructor will take in the name, max hp's, max and min damage, chance to hit, chance to heal, max heal, min heal, as well as attack speed. Everything except the chance to heal will be passed to the super class.

You will modify the setHP(int hpIn) method to include a chance to heal. you will pass the hpIn to the super. If the monster is still alive you will generate a random number to determine if the monster will heal itself. If the random number is less than the chance to heal you will generate another random number between the max and min heal. You will pass this positive number to the super.setHp(hpOut).

You will create 6 more classes. 3 classes will inherit from the hero class, Warrior, thief, and sorcerer. 3 will inherit from the monster class, gremlin, ogre, and skeleton. You can substitute your own classes if you wish. Each class will modify the attack method to represent each new classes specialty. The warrior can crush an apponent, the thief can get a more attacks, the sorcerer can both attack and heal itself. The gremlin is similar to the sorcerer and the skeleton is similar to the thief. We will be discussing the details in class so pay attention.

Finally, each class will implement the show info method as inherited from the appropriate class. The main class will implement game play. It will proceed as follows:

Human player creates character and chooses type. The computer auto generates an opponent. The human player will take their turn, then the computer. If either dies during the others turn they don't get another. You should print out the results of each turn as they happen.

Explanation / Answer

package thisPackage;

import java.util.Random;

public abstract class DungeonCharacter {
  
   String name;
  
   int MaxHP;

   int HP;

   int dmax;
  
   int dmin; // minimum and maximum damage

   double chanceInt;// chance to hit

   int attackSpeed; // speed of attack

   public DungeonCharacter(String name, int hP, int dmax, int dmin, double chanceInt, int attackSpeed) {
      
       this.name = name;
       HP = hP;
       MaxHP= HP;
       this.dmax = dmax;
       this.dmin = dmin;
       this.chanceInt = chanceInt;
       this.attackSpeed = attackSpeed;
   }
   public boolean isAlive()
   {
       if (this.HP <= 0)
               return false;
       return true;
                      
   }
   public boolean successfulAction(double chance)
   {
       Random r = new Random();
       int c = r.nextInt(100);
      
       if(c <= chance )
           return true;
       else
           return false;
   }
  
   public String getName(String name) {
       return this.name;
   }
   public void setHP(int hP) {
      
      
       this.HP+=hP;
          
   }
   public int getNumTurns(int mAttackSpeed)
   {
       if (this.attackSpeed<mAttackSpeed)
           return 1;
       else
           return (int)(this.attackSpeed/mAttackSpeed);
   }
   public int getMaxHP()
   {
       return this.MaxHP;
   }
   public abstract void showInfo();
   public abstract void attack();
}

package thisPackage;

import java.util.Random;

public class Hero extends DungeonCharacter{

   double chanceToBlock;

   public Hero(String name, int hP, int dmax, int dmin, double chanceInt, int attackSpeed,double chanceToBlock) {
       super( name, hP, dmax, dmin, chanceInt, attackSpeed);
       this.chanceToBlock = chanceToBlock;
   }
   @Override
   public void setHP(int hPIn) {
      
       Random r = new Random();
       int c = r.nextInt(100);
       if(c < this.chanceToBlock)
           super.setHP(0);
       else
           super.setHP(-1*hPIn);
          
   }
   public void showInfo() {
      
   }
  
   public void attack()
   {
      
   }       
}

package thisPackage;

import java.util.Random;

public class Monster extends DungeonCharacter{

  
   double chanceToHeal;
   int maxHeal;
   int minHeal;
  
   public Monster(String name, int hP, int dmax, int dmin, double chanceInt, int attackSpeed,double chanceToHeal,int minHeal,int maxHeal)
   {
       super(name, hP, dmax, dmin, chanceInt, attackSpeed);
       this.chanceToHeal = chanceToHeal;
       this.maxHeal = maxHeal;
       this.minHeal = minHeal;
      
   }
   @Override
   public void setHP(int hPIn) {
      
       super.setHP(-1*hPIn);
       Random r = new Random();
       int c = r.nextInt(100);
      
       if(this.isAlive())
       {
           if(c<this.chanceToHeal)
           {
               c = r.nextInt(maxHeal-minHeal+1);
               super.setHP(c);
           }
       }
      
          
   }

   @Override
   public void showInfo() {
      
      
   }
   @Override
   public void attack()
   {
      
   }
}