Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1: Battle Game (50 points) For this question, you will write a number of classes to create a battle game between a player and
Question 1: Battle Game (50 points) For this question, you will write a number of classes to create a battle game between a player and a monster. Your code for this question will go in multiple .java files we strongly recommend that you complete all the warm-up questions before starting this problem Note that in addition to the required methods below, you are free to add as many other private methods as you want (a) Character Class character .java represents a character in our battle game. The monster and the player will both be instances of the Character class, each with their own attributes e Character class should contain the following (private) attributes: A String name A double attack value A double maximum health value A double current health value A int number of wins in the battle game Here are the required public methods for this class. Note that you will also have to add getters and setters for the instance attributes as needed. 1) A constructor The constructor for the character class takes one string, two doubles and one int as input. These parameters represent the name, attack value, maximum health, and number of wins in the battle game for the character, in that order. Note that the current health of a new character is the same as the maximum health 2) The toString method This method returns a string consisting of the character's name and current health. Format the String in any way you want. This method will be very handy for debugging your code, and will be used during the battle game to keep track of the health of each character 3) calcAttack method This method calculates how much attack damage one character does in a battle. The calculation is as follows: Take the character's attack value and multiply it by a random value between 0.3 (inclusive) and 0.7 (exclusive). Return this value as a double. Use the Random class to generate the random numbers, and do not use a seed 4) take Damage method In this method, we take the damage done to this character as a double parameter, and then we subtract this value from the character's current health. This method does not return anything. 5) increasewins method This method will increase the number of wins by the character by one, and does not return anything. This method will be called when the character wins the battle game. Question 1: Battle Game (50 points) For this question, you will write a number of classes to create a battle game between a player and a monster. Your code for this question will go in multiple .java files we strongly recommend that you complete all the warm-up questions before starting this problem Note that in addition to the required methods below, you are free to add as many other private methods as you want (a) Character Class character .java represents a character in our battle game. The monster and the player will both be instances of the Character class, each with their own attributes e Character class should contain the following (private) attributes: A String name A double attack value A double maximum health value A double current health value A int number of wins in the battle game Here are the required public methods for this class. Note that you will also have to add getters and setters for the instance attributes as needed. 1) A constructor The constructor for the character class takes one string, two doubles and one int as input. These parameters represent the name, attack value, maximum health, and number of wins in the battle game for the character, in that order. Note that the current health of a new character is the same as the maximum health 2) The toString method This method returns a string consisting of the character's name and current health. Format the String in any way you want. This method will be very handy for debugging your code, and will be used during the battle game to keep track of the health of each character 3) calcAttack method This method calculates how much attack damage one character does in a battle. The calculation is as follows: Take the character's attack value and multiply it by a random value between 0.3 (inclusive) and 0.7 (exclusive). Return this value as a double. Use the Random class to generate the random numbers, and do not use a seed 4) take Damage method In this method, we take the damage done to this character as a double parameter, and then we subtract this value from the character's current health. This method does not return anything. 5) increasewins method This method will increase the number of wins by the character by one, and does not return anything. This method will be called when the character wins the battle game
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started