Advertisement
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 = new ArrayList<Fighter>();
- Scanner console = new Scanner(System.in);
- boolean inLoop = true;
- do{
- System.out.println("What is the name of the fighter?");
- String name = console.next();
- System.out.println("What is the Attack stat of " + name + "?");
- int atk = console.nextInt();
- System.out.println("What is the Defense stat of " + name + "?");
- int def = console.nextInt();
- Fighter currentFighter = new Fighter(name, atk, def);
- fighters.add(currentFighter);
- System.out.println("Add 1 more fighter? Type in 'true' to confirm or 'false' to cancel.");
- inLoop = console.nextBoolean();
- } while(inLoop);
- Collections.sort(fighters, new Fighter("None", 0, 0));
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement