/* Note: This code is very messy and does not follow great style Please do not follow this code as an example for classes you may write Hello there! Welcome to the world of Pokémon! My name is Oak! People call me the Pokémon Prof! This world is inhabited by creatures called Pokémon! For some people, Pokémon are pets. Other use them for fights. Every Pokemon has either 1 or 2 types. Each type can be "super-effective" against other types, similar to rock-paper-scissors. They also stats for various categories, what generation of the video game they were introduced, and whether or not it is a legendary pokemon. */ import java.util.*; public class Pokemon { public int number; public String name; public String type1; public String type2; public int totalStats; public int hp; public int attack; public int defense; public int specialAttack; public int specialDefense; public int speed; public int generation; public boolean legendary; // Takes in a comma separated line of data for a // Pokemon and constructs an instance of it with // the proper fields assigned public Pokemon(String info) { String[] stats = info.split(","); number = Integer.parseInt(stats[0]); name = stats[1]; type1 = stats[2]; type2 = stats[3]; totalStats = Integer.parseInt(stats[4]); hp = Integer.parseInt(stats[5]); attack = Integer.parseInt(stats[6]); defense = Integer.parseInt(stats[7]); specialAttack = Integer.parseInt(stats[8]); specialDefense = Integer.parseInt(stats[9]); speed = Integer.parseInt(stats[10]); generation = Integer.parseInt(stats[11]); legendary = stats[12].equals("True"); } // Returns the type(s) of the Pokemon as a String // eg. "Fire" or "Electric/Water" public String getType() { if (type2.isEmpty()) { return type1; } else { return type1 + "/" + type2; } } // Returns the types that this Pokemon is super-effective // against as a Set of Strings public Set superEffectiveAgainst() { Set result = new HashSet(); result.addAll(getTypeChart().get(type1)); result.addAll(getTypeChart().get(type2)); return result; } // Returns a map of what each type is super-effective against // where the type is String key and the value is a set of types // that the type is super-effective against public static Map> getTypeChart() { Map> result = new HashMap>(); result.put("", new HashSet()); result.put("Normal", new HashSet()); List s = Arrays.asList("Grass", "Ice", "Bug", "Steel"); result.put("Fire", new HashSet(s)); s = Arrays.asList("Fire", "Ground", "Rock"); result.put("Water", new HashSet(s)); s = Arrays.asList("Water", "Flying"); result.put("Electric", new HashSet(s)); s = Arrays.asList("Water", "Ground", "Rock"); result.put("Grass", new HashSet(s)); s = Arrays.asList("Grass", "Ground", "Flying", "Dragon"); result.put("Ice", new HashSet(s)); s = Arrays.asList("Normal", "Ice", "Rock", "Dark", "Steel"); result.put("Fighting", new HashSet(s)); s = Arrays.asList("Grass", "Fairy"); result.put("Poison", new HashSet(s)); s = Arrays.asList("Fire", "Electric", "Poison", "Rock", "Steel"); result.put("Ground", new HashSet(s)); s = Arrays.asList("Grass", "Fighting", "Bug"); result.put("Flying", new HashSet(s)); s = Arrays.asList("Fighting", "Poison"); result.put("Psychic", new HashSet(s)); s = Arrays.asList("Grass", "Psychic", "Dark"); result.put("Bug", new HashSet(s)); s = Arrays.asList("Fire", "Ice", "Flying", "Bug"); result.put("Rock", new HashSet(s)); s = Arrays.asList("Psychic", "Ghost"); result.put("Ghost", new HashSet(s)); s = Arrays.asList("Dragon"); result.put("Dragon", new HashSet(s)); s = Arrays.asList("Psychic", "Ghost"); result.put("Dark", new HashSet(s)); s = Arrays.asList("Steel", "Rock", "Fairy"); result.put("Steel", new HashSet(s)); s = Arrays.asList("Fighting", "Dragon", "Dark"); result.put("Fairy", new HashSet(s)); return result; } // Returns a set of all the types in Pokemon public static Set getAllTypes() { List s = Arrays.asList("Normal", "Fire", "Water", "Electric", "Grass", "Ice", "Fighting", "Poison", "Ground", "Flying", "Psychic", "Bug", "Rock", "Ghost", "Dragon", "Dark", "Steel", "Fairy"); return new HashSet(s); } }