ssunlimited

Fighter Rankings

Jun 27th, 2022 (edited)
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Fighter implements Comparator<Fighter> {
  4.    
  5.    public String name;
  6.    public int atk, def, powerLevel;
  7.    public static List<Fighter> fighters = new ArrayList<Fighter>();
  8.  
  9.    public Fighter(String name, int atk, int def){
  10.       this.name = name;
  11.       this.atk = atk;
  12.       this.def = def;
  13.       this.powerLevel = CalculatePowerLevel(atk, def);
  14.       }
  15.    
  16.    public int CalculatePowerLevel(int atk, int def){
  17.       return atk * def;
  18.    }
  19.    
  20.    public static void main(String[] args){
  21.       fighters = Arrays.asList(new Fighter ("Krillin", 50, 20), new Fighter("Yamcha", 20, 30));
  22.       Collections.sort(fighters, new Fighter("None", 1, 1));
  23.       System.out.println("The strongest fighters by power level are: ");
  24.       for(Fighter fighter : fighters) System.out.println(fighter.name);
  25.    }
  26.    
  27.    @Override
  28.    public int compare(Fighter a, Fighter b){
  29.       return b.powerLevel - a.powerLevel;
  30. }
  31.  
  32. }
Add Comment
Please, Sign In to add comment