import java.util.ArrayList; import java.util.Collections; class Pokemon implements Comparable { private String name; private String team; protected String type; protected int hp; protected int attack; protected boolean knockedOut; public Pokemon(String name, String type, String team) { this.name = name; this.type = type; this.hp = 40; this.attack = 25; this.knockedOut = false; this.team = team; } public void getRekt(int a) { this.hp -= a; if (this.hp <= 0) { this.knockedOut = true; } } public int compareTo(Pokemon other) { if (this.knockedOut && !other.knockedOut) { return 1; } if (!this.knockedOut && other.knockedOut) { return -1; } if (!other.type.equals(this.type)) { return this.type.compareTo(other.type); } return this.name.compareTo(other.name); } public String toString() { String line = "Team " + this.team + ": "; line += this.name + " (" + this.type + ")"; if (this.knockedOut) { line += " (xxxxxx)"; } return line; } static private void printDozPokemon(ArrayList roster) { Collections.sort(roster); for (Pokemon p : roster) { System.out.println(p); } } public static void main(String args[]) { ArrayList poks = new ArrayList(); Pokemon s = new Pokemon("Scyther", "Bug", "A"); poks.add(s); Pokemon bf = new Pokemon("Butterfree", "Bug", "A"); poks.add(bf); Pokemon jp = new Pokemon("Jigglypuff", "Fairy", "B"); poks.add(jp); Pokemon sw = new Pokemon("Swirlix", "Fairy", "B"); poks.add(sw); printDozPokemon(poks); System.out.println("Butterfree, I choose you!"); System.out.println("Swirlix, I choose you!"); bf.getRekt(sw.attack); sw.getRekt(bf.attack); System.out.println("Jigglypuff, go help Swirlix!"); jp.getRekt(bf.attack); jp.getRekt(bf.attack); printDozPokemon(poks); } }