JAVA, The screenshots of the code and results require. Thanks ----------------------------------------------------------
Posted: Sat May 14, 2022 6:50 pm
JAVA, The screenshots of the code and results
require.
Thanks
------------------------------------------------------------------------------
// BELOW IS THE INTERFACE CALLED Combatant
public interface Combatant {
//create two abstract methods, attack and get attacked. Since these
are abstract, we do not provide an implementation about how these
methods should behave.
/**
* purpose - This combatant object attacks a target combatant
object,
* inflicting damage on the target combatant object's health.
*
* @param defender - ref variable to the combatant object being
attacked
* @param damageDealt - amount of hitPoints delivered upon the
defending
* combatant object.
*/
public abstract void attack(Combatant defender, int
damageDealt);
/**
* purpose - This entity is being attacked by a attacking combatant
object,
* taking damage to this defending combatant object's health.
*
* @param attacker - ref variable to the combatant object
attacking
* @param damageSustained - amount of hitPoints sustained by this
defending
* combatant object.
*/
public abstract void getAttacked(Combatant attacker, int
damageSustained);
}
__________________________________________________________________
// BELOW IS THE CLASS CALLED Gladiator
class Gladiator{
Club weapon;
Rags armor;
String name;
//default constructor
Gladiator(){
this(new Club(),new Rags(),"The Masked");
}
//Parametered Constructor
Gladiator(Club weapon,Rags armor,String name){
this.weapon=weapon;
this.armor=armor;
this.name="The Masked";
}
//Getters and Setters
public Club getWeapon() {return weapon;}
public void setWeapon(Club weapon) {this.weapon = weapon;}
public Rags getArmor() {return armor;}
public void setArmor(Rags armor) {this.armor = armor;}
----------------------------------------------------------------------------------------------------------
*****Instruction*****
*MODIFY the Gladiator class to
implement the Combatant
interface
- This means that you must provide a concrete implementation for
the attack and getAttacked
methods.
- The attack method should print a message that
says the gladiator is attacking and then call the
getAttacked of the target.
- The getAttacked method should print a message about the
gladiator getting ready to be attacked, and then
-- deduct the damage from the gladiator's
currentHealth
-- If the gladiator has 1 or more health, print a message that
it is still alive.
-- deduct the damage from the gladiator's
currentHealth
-- If the gladiator has 1 or more health, print a message that
it is still alive.
-- If not, print a message about the gladiator dying.
*CREATE a class called Monster that
implements Combatant
- Monster should have private instance
variables
-- currentHealth - The amount of health the
monster has
-- damageDealt - The damage the monster does
when it attacks
-- treasureCarried - The amount of silver the
monster has
- Create getters, setters, and a toString
method for Monster
- Create a zero argument constructor that initializes all
instance variables to 0
- Create a full argument constructor that sets the instance
variables to parameters passed to it.
- Be sure to include the two abstract methods from
Combatant. But leave them abstract.
require.
Thanks
------------------------------------------------------------------------------
// BELOW IS THE INTERFACE CALLED Combatant
public interface Combatant {
//create two abstract methods, attack and get attacked. Since these
are abstract, we do not provide an implementation about how these
methods should behave.
/**
* purpose - This combatant object attacks a target combatant
object,
* inflicting damage on the target combatant object's health.
*
* @param defender - ref variable to the combatant object being
attacked
* @param damageDealt - amount of hitPoints delivered upon the
defending
* combatant object.
*/
public abstract void attack(Combatant defender, int
damageDealt);
/**
* purpose - This entity is being attacked by a attacking combatant
object,
* taking damage to this defending combatant object's health.
*
* @param attacker - ref variable to the combatant object
attacking
* @param damageSustained - amount of hitPoints sustained by this
defending
* combatant object.
*/
public abstract void getAttacked(Combatant attacker, int
damageSustained);
}
__________________________________________________________________
// BELOW IS THE CLASS CALLED Gladiator
class Gladiator{
Club weapon;
Rags armor;
String name;
//default constructor
Gladiator(){
this(new Club(),new Rags(),"The Masked");
}
//Parametered Constructor
Gladiator(Club weapon,Rags armor,String name){
this.weapon=weapon;
this.armor=armor;
this.name="The Masked";
}
//Getters and Setters
public Club getWeapon() {return weapon;}
public void setWeapon(Club weapon) {this.weapon = weapon;}
public Rags getArmor() {return armor;}
public void setArmor(Rags armor) {this.armor = armor;}
----------------------------------------------------------------------------------------------------------
*****Instruction*****
*MODIFY the Gladiator class to
implement the Combatant
interface
- This means that you must provide a concrete implementation for
the attack and getAttacked
methods.
- The attack method should print a message that
says the gladiator is attacking and then call the
getAttacked of the target.
- The getAttacked method should print a message about the
gladiator getting ready to be attacked, and then
-- deduct the damage from the gladiator's
currentHealth
-- If the gladiator has 1 or more health, print a message that
it is still alive.
-- deduct the damage from the gladiator's
currentHealth
-- If the gladiator has 1 or more health, print a message that
it is still alive.
-- If not, print a message about the gladiator dying.
*CREATE a class called Monster that
implements Combatant
- Monster should have private instance
variables
-- currentHealth - The amount of health the
monster has
-- damageDealt - The damage the monster does
when it attacks
-- treasureCarried - The amount of silver the
monster has
- Create getters, setters, and a toString
method for Monster
- Create a zero argument constructor that initializes all
instance variables to 0
- Create a full argument constructor that sets the instance
variables to parameters passed to it.
- Be sure to include the two abstract methods from
Combatant. But leave them abstract.