Question: Solution Description Create files Bender. java, WaterBender.java, FireBender.java, and Battle.java. Based on the description given for each variable and method for each class, you will

 Solution Description Create files Bender. java, WaterBender.java, FireBender.java, and Battle.java. Basedon the description given for each variable and method for each class,you will have to decide whether the variables/method should be static, aswell as its appropriate visibility modifier. Bender . java This file definesa Bender of the elements. You must not be able to create

Solution Description Create files Bender. java, WaterBender.java, FireBender.java, and Battle.java. Based on the description given for each variable and method for each class, you will have to decide whether the variables/method should be static, as well as its appropriate visibility modifier. Bender . java This file defines a Bender of the elements. You must not be able to create an instance of this class (there is a keyword that prevents us from creating instances of a class). Variables Variables must not be allowed to be directly modified by all classes. You can choose to have your variables visible by your subclasses or by no classes at all. The Bender class must have these variables. - name - the name of the Bender, represented as a String - strength - the strength of the Bender, represented as an integer - health - the health of the Bender, represented as an integer Constructors - A 3-arg constructor that takes in the name, strength, and health. You can assume that all strength and health values passed in will always be positive and nonzero integers Methods Do not create any other methods than those specified. Any extra methods will result in point deductions. All methods must have the proper visibility to be used where it is specified they are used. - isAlive( ) - Returns whether the Bender is alive (health is positive). - attack(Bender b) Each attack method is unique to the specific bender. There is no implementation for this method within the Bender class. Any concrete class that extends the Bender class must provide a method definition for this method. Does not return anything. - equals - Two Benders are equal if all the instance variables are equal. - Must be a valid override to the equals method defined in Object class. Use this information to determine the parameter type(s) and return type. - tostring() Returns a String describing the Bender as follows (Note: replace the values in brackets [] with the actual value): - My name is [name]. I am a bender. My strength is [strength] and my current health is [health]. - Must override toString() method defined in Object class - Getters for all variables, setters as needed (depending on your variable visibility, you may require no setters at all). WaterBender.java This file defines a WaterBender. A WaterBender has power over the element water. This class will be a subclass of Bender. Variables All variables must not be allowed to be directly modified outside the class. The WaterBender class must have these variables: - healer - whether the WaterBender is a healer, represented as a boolean Constructors You must use appropriate constructor chaining for your constructors. The constructors must take the variables in the specified order. (Hint: Refer to L10: Constructors as L12: Coding Basics and More Visibility Modifiers for constructor chaining and constructor chaining when a superclass is involved). - A 4-arg constructor that takes in a name, strength, health, and healer and sets all fields accordingly. - A 1-arg constructor that only takes in name and assigns the following default values: strength: 40 health: 80 healer: false Methods Do not create any other methods than those specified. Any extra methods will result in point deductions. All methods must have the proper visibility to be used where it is specified they are used. - attack(Bender b) A WaterBender can only attack if they are alive. The Bender passed in is attacked by the WaterBender. - If the Bender passed is a FireBender, reduce the health of the attacked FireBender by the strength of the WaterBender attacking - If the Bender passed is a WaterBender (accidental attack), reduce the health of the attacked WaterBender by 1. - For both cases, if the health of the attacked Bender drops below 0 , set it to 0 . - This method should not return anything. - heal(WaterBender wb) - If the instance the method is being invoked on is not a healer or either that instance or the passed WaterBender are not alive, return from the method (do nothing). Otherwise, increase the health of the passed WaterBender by 20 if the passed WaterBender is not a healer, and by 40 if the passed WaterBender is a healer. - equals - This method must override Bender's equals method - Two WaterBenders are equal if they both have the same name, strength, health, and healer attributes. You must call the equals method from the Bender class and use its value to receive full credit - tostring() - This method must override the toString() method in the Bender superclass - Returns a String describing the WaterBender as follows (Note: Replace the values in brackets with the actual value, and use can/cannot depending on whether the WaterBender is a healer): - My name is [name]. I am a bender. My strength is [strength] and my current health is [health]. With my waterbending, I [can/cannot] heal others. For example: - My name is Jinbe. I am a bender. My strength level is 100, and my current health is 100. With my waterbending, I cannot heal others. - You must call the toString() method from the Bender class and use its value to receive full credit - Getters for all variables, no setters. FireBender.java This file defines a FireBender. A FireBender has power over the element fire. This class will be a subclass of Bender. Variables All variables must not be allowed to be directly modified outside the class. The FireBender class must have these variables: - firesourcestrength - this variable is shared across all instances of the FireBender class, and represents with a double how effective the attacks of FireBenders are due to nearby sources of fire. It You must use appropriate constructor chaining for your constructors. The constructors must take the variables in the specified order. (Hint: Refer to L10: Constructors as L12: Coding Basics and More Visibility Modifiers for constructor chaining and constructor chaining when a superclass is involved). - A 3-arg constructor that takes in a name, strength, and health and sets all fields accordingly. - A 1-arg constructor that only takes in name and assigns the following default values: strength: 60 health: 50 Methods Do not create any other methods than those specified. Any extra methods will result in point deductions. All methods must have the proper visibility to be used where it is specified they are used. - attack(Bender b) - A FireBender can only attack if they are alive. - The Bender passed in is attacked by the FireBender. - If the Bender passed is a WaterBender, reduce the health of the attacked WaterBender by the strength of the FireBender attacking multiplied by fireSourcestrength - If the Bender passed is a FireBender (accidental attack), reduce the health of the attacked FireBender by fireSourceStrength. - For both cases: - Round down the result (cast to int) after the multiplication - If the health of the attacked Bender drops below 0 , set it to 0 . - AFTER the attack, decrease fireSourceStrength as described in the variable - This method should not return anything. - replenishFireSources() - A FireBender can replenish the nearby sources of fire. If the FireBender has less than 50 of strength, it sets fireSourcestrength to 0.8 if it's currently less than that. Otherwise, it sets firesourcestrength to 1. - equals - This method must override Bender's equals method - Two FireBenders are equal if they both have the same name, strength, and health. Unlike the Bender's equals, which only checks if the object is a Bender, this method should check if the object is a FireBender. A WaterBender with same name, strength, and health to a FireBender is NOT equal to it under FireBender's equals method. - You must call the equals method from the Bender class and use its value to receive full credit - tostring() - This method must override the toString() method in the Bender superclass - Returns a String describing the FireBender as follows (Note: Replace the values in brackets with the actual value, and use can/cannot depending on whether the WaterBender is a healer): - My name is [name]. I am a bender. My strength is [strength] and my current health is [health]. I bend fire. You must call the toString() method from the Bender class and use its value to receive full credit - Getters for all variables, no setters. ttle.java (optional) s Java file is a driver, meaning it will contain and run WaterBender and FireBender instances and "drive" their ues according to a simulated set of actions. You'll write a main method. - You will receive in the args array the number of WaterBenders and the number of FireBenders, in that order. Make arrays of WaterBender and FireBender such that it can contain the required number of each. - After that, you will receive through console input many lines that in number will match the number of WaterBenders and FireBenders. The first lines contain the information to instantiate the WaterBenders, and the next lines contain the information to instantiate the FireBenders. The number of them is determined by the length of the arrays, create the instances and put them in the array in the order they are received from console input: Input format: - WaterBender: name strength health [yeso] - FireBender: name strength health - For both, you can assume the name won't have spaces - Once all Benders are created, the battle can begin. The battle will proceed until there are no alive benders from either nation, alternating turns between a WaterBender and a FireBender (The first WaterBender acts, then the first FireBender acts, then the second WaterBender acts, then the second FireBender acts, and so on. When all Benders of a nation have acted, start over from the beginning of that nation's array. When a Bender isn't alive, move on to the first alive Bender of the nation that has the turn following the order in the array and going back to the beginning as necessary. Hint: the modulus operator can be handy for this procedure) - After selecting the attacking Bender, print the following to the console, without a newline: - "[name] (Fire Nation/Water Nation): " - Replace name with the name of the Bender and put "Fire Nation" or "Water nation" accordingly. The parentheses are part of the output. Leave a space after the colon. If the Bender is a WaterBender - The action (read from console input the entire line) will be based on this format: - attack [name of any Bender] - heal [name of any WaterBender] - Determine which Bender they are acting on, and call the appropriate method on the WaterBender that has the turn - You can assume that there will be a Bender with the provided name that is valid for the selected action If the Bender is a FireBender - The action (read from console input the entire line) will be based on this format: - attack [name of any Bender] - replenish - If applicable, determine which Bender they are acting on. Then, call the appropriate method on the Fire that has the turn - You can assume that there will be a Bender with the provided name when the FireBender attacks After every action (from any of the nations), check if there's any nation for which all their Benders aren't alive. If that's the case, the battle ends. Print "The Water Nation wins" or "The Fire Nation wins" depending on who won the battle. That's the end of the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!