Java please
We want you to implement a java class that will show how players can keep track of their spells and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your SpellException class: – A private int named mana that represents how much mana the player has . A private String[] named spells that is an array of spells – A private int[] named spellDamage that is an array of damage for each spell – A private int[] named spellCost that is an array of mana cost for each spell . A private String named recentSpell that stores the most recent used spell; . A private int named spellIndex that stores where the most recent used spell is. Your class will provide the following constructor: – A constructor that takes in mana, spellDamage, and spellCost In the constructor, throw an exception if any of the array length is 0 or don’t equal cach other length. Throw an exception if mana is less than 0 as well. Your class will also provide the following methods: – Getter and setter for private field mana o Throw an exception if mana is negative – A method called getSpell that takes in no arg and returns a random spell. • Overload getSpell so it takes in a int and return the spell at that location o Throw an exception if index the int is out of bound or cost of mana is greater than the current amount of mana the player has o Hint: Don’t forget to set mana after getting spell A void method called addSpell that takes in the new spell, damage, and manaCost and adds it to the spells array. Hint: if spells get updated, so does spellDamage and spellCost. A void method called remove Spell that takes in no arg and removes a random spell from the spells array – Overload removeSpell so it takes in an int and removes the spell at that location O Update all arrays where needed A void method called listSpell that prints out all the current spells you have, how much damage the spell deals and how much mana it cost. Use printf to format the output to look like: 1. Skill 1 Mana cost: x mp Damage: y atk 2. Skill 2 Mana cost x mp Damage: y atk And so forth (hint: lookup format specifier for more info on how to format output using printf) A getter for spellCost and spellDamage that returns the cost and damage of the most recently used spell. A adder method to add the new spellDamage and spellCost to their respective array when a spell is added A remover method to remove the old spellDamage and spellCost to their respective array when a spell is removed A toString method that outputs “You the great archmage” + how much mana you have + the most recent spell you used with how much it cost and how much damage it deals. You will then add a main method to your class that tests all the features of your class: – A SpellException Object that takes 3 array of different sizes to test the array size different exception A SpellException Object that takes in any empty array or negative mana to test the argument exception A SpellExcpetion Object that takes in 1000 for the mana, {“slash”, “fireball”, “pounce”) for the spells, 100, 2000, 100} for the spellDamage and {50,2000,50) for the spellCost o Use getSpell(1) to retrieved fireball and see if an exception appears o Use getSpell() to retrieved a random spell o Use listSpell to print out all the spells and toString to see the player information and most recently used spell. o Use addSpell to add a spell of your choice and print out the list of spell again o Use either removeSpell to remove a spell and print out the list of spell again Show transcribed image text We want you to implement a java class that will show how players can keep track of their spells and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your SpellException class: – A private int named mana that represents how much mana the player has . A private String[] named spells that is an array of spells – A private int[] named spellDamage that is an array of damage for each spell – A private int[] named spellCost that is an array of mana cost for each spell . A private String named recentSpell that stores the most recent used spell; . A private int named spellIndex that stores where the most recent used spell is. Your class will provide the following constructor: – A constructor that takes in mana, spellDamage, and spellCost In the constructor, throw an exception if any of the array length is 0 or don’t equal cach other length. Throw an exception if mana is less than 0 as well. Your class will also provide the following methods: – Getter and setter for private field mana o Throw an exception if mana is negative – A method called getSpell that takes in no arg and returns a random spell. • Overload getSpell so it takes in a int and return the spell at that location o Throw an exception if index the int is out of bound or cost of mana is greater than the current amount of mana the player has o Hint: Don’t forget to set mana after getting spell A void method called addSpell that takes in the new spell, damage, and manaCost and adds it to the spells array. Hint: if spells get updated, so does spellDamage and spellCost. A void method called remove Spell that takes in no arg and removes a random spell from the spells array
– Overload removeSpell so it takes in an int and removes the spell at that location O Update all arrays where needed A void method called listSpell that prints out all the current spells you have, how much damage the spell deals and how much mana it cost. Use printf to format the output to look like: 1. Skill 1 Mana cost: x mp Damage: y atk 2. Skill 2 Mana cost x mp Damage: y atk And so forth (hint: lookup format specifier for more info on how to format output using printf) A getter for spellCost and spellDamage that returns the cost and damage of the most recently used spell. A adder method to add the new spellDamage and spellCost to their respective array when a spell is added A remover method to remove the old spellDamage and spellCost to their respective array when a spell is removed A toString method that outputs “You the great archmage” + how much mana you have + the most recent spell you used with how much it cost and how much damage it deals. You will then add a main method to your class that tests all the features of your class: – A SpellException Object that takes 3 array of different sizes to test the array size different exception A SpellException Object that takes in any empty array or negative mana to test the argument exception A SpellExcpetion Object that takes in 1000 for the mana, {“slash”, “fireball”, “pounce”) for the spells, 100, 2000, 100} for the spellDamage and {50,2000,50) for the spellCost o Use getSpell(1) to retrieved fireball and see if an exception appears o Use getSpell() to retrieved a random spell o Use listSpell to print out all the spells and toString to see the player information and most recently used spell. o Use addSpell to add a spell of your choice and print out the list of spell again o Use either removeSpell to remove a spell and print out the list of spell again
Expert Answer
Answer to We want you to implement a java class that will show how players can keep track of their spells and throw exceptions whe…