Has anyone done this before? Modify your BattleManager class Add a method called
ID: 3713472 • Letter: H
Question
Has anyone done this before? Modify your BattleManager class Add a method called battle. This method takes, as parameters, 2 heroes and a number of rounds to fight. Your battle method should use a loop to run the round methods, with the heroes as input to round. Battle should return the hero with the most health after all rounds have completed. You can handle a tie how ever you like AS LONG AS A HERO OBJECT YOU CONSIDER THE WINNER IS RETURNED Add a method called tournament. This method takes, as parameters, an array of heroes. This method runs a single elimination tournament on all the heroes. The method should call the battle method for pairs of heroes in the array. Each battle in the tournament lasts for 3 rounds. After the tournament has completed, return the hero object that is the winner of the entire tournament Test your changes to the battle manager by creating a main class that Creates a battle manager Creates 2 heroes and battle them for 5 rounds. using the battle method. Creates an array of 5 hero objects call the tournament method with your array
Explanation / Answer
package testswing.upload; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; public class BattleManager { Random ran = new Random(); public String battle(String hero1,String hero2,Integer rounds){ Integer hero1_health=0; Integer hero2_health=0; for(int i=0;ihero2_health) return hero1; else if(hero2_health>hero1_health){ return hero2; } else { if (rounds(hero1, hero2) == hero1) return hero1; else { return hero2; } } } public String rounds(String hero1,String hero2){ int x = ran.nextInt(2); if(x==0){ return hero1; } else{ return hero2; } } public String tournament(String[] heros){ Integer[] points=new Integer[heros.length]; for (int x=0;xRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.