JAVA, The screenshots of the code and results require. Thanks ----------------------------------------------------------

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

JAVA, The screenshots of the code and results require. Thanks ----------------------------------------------------------

Post by answerhappygod »

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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply