Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Fighter implements Comparator<Fighter> {
- public String name;
- public int atk, def, powerLevel;
- public static List<Fighter> fighters = new ArrayList<Fighter>();
- public Fighter(String name, int atk, int def){
- this.name = name;
- this.atk = atk;
- this.def = def;
- this.powerLevel = CalculatePowerLevel(atk, def);
- }
- public int CalculatePowerLevel(int atk, int def){
- return atk * def;
- }
- public static void main(String[] args){
- fighters = Arrays.asList(new Fighter ("Krillin", 50, 20), new Fighter("Yamcha", 20, 30));
- Collections.sort(fighters, new Fighter("None", 1, 1));
- System.out.println("The strongest fighters by power level are: ");
- for(Fighter fighter : fighters) System.out.println(fighter.name);
- }
- @Override
- public int compare(Fighter a, Fighter b){
- return b.powerLevel - a.powerLevel;
- }
- }
Add Comment
Please, Sign In to add comment