ilianrusev

arena

Jun 22nd, 2019
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None
  1. package arena;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Comparator;
  5. import java.util.List;
  6. import java.util.stream.Collectors;
  7.  
  8. public class FightingArena {
  9. private String name;
  10. private List<Gladiator> gladiators;
  11.  
  12. public FightingArena(String name) {
  13. this.name = name;
  14. this.gladiators = new ArrayList<>();
  15. }
  16.  
  17. public String getName() {
  18. return name;
  19. }
  20.  
  21. public void add(Gladiator gladiator){
  22. this.gladiators.add(gladiator);
  23. }
  24.  
  25.  
  26. public void remove(String name){
  27. this.gladiators.removeIf(gladiator -> gladiator.getName().equals(name));
  28. }
  29.  
  30. public Gladiator getGladiatorWithHighestStatPower(){
  31. return this.gladiators.stream()
  32. .sorted((a,b) -> b.getStatPower() - a.getStatPower() )
  33. .collect(Collectors.toList())
  34. .get(0);
  35. }
  36.  
  37. public Gladiator getGladiatorWithHighestWeaponPower(){
  38. return this.gladiators.stream()
  39. .sorted((a,b) -> b.getWeaponPower() - a.getWeaponPower() )
  40. .collect(Collectors.toList())
  41. .get(0);
  42. }
  43.  
  44. public Gladiator getGladiatorWithHighestTotalPower(){
  45. return this.gladiators.stream().max(Comparator.
  46. comparingInt(gladiator -> gladiator.getTotalPower())).get();
  47.  
  48. }
  49.  
  50. public int getCount(){
  51. return this.gladiators.size();
  52. }
  53.  
  54. @Override
  55. public String toString() {
  56. return String.format("%s – %d gladiators are participating."
  57. , this.getName(), getCount());
  58. }
  59. }
RAW Paste Data Copied