import java.util.*; import java.io.*; import java.util.stream.*; public class PokemonSearch { public static void main(String[] args) throws FileNotFoundException{ Scanner s = new Scanner(new File("pokemon.csv")); s.nextLine(); // A list of all the Pokemon in the file List pokedex = new LinkedList(); // A map from each Pokemon name to it's Pokemon object, Map pokeMap = new HashMap(); while (s.hasNextLine()) { String line = s.nextLine(); Pokemon pokemon = new Pokemon(line); pokedex.add(pokemon); pokeMap.put(pokemon.name, pokemon); } // Problem 1: Print out all the pokemon names pokedex // List - all the Pokemon .stream() // Stream - all the Pokemon .map((pokemon) -> pokemon.name) // Stream - all the Pokemon names .forEach(System.out::println); // void -> print out the Pokemon names // Problem 2: Print out the names of only the pokemon from the first generation pokedex .stream() .filter((pokemon) -> pokemon.generation == 1) // All Pokemon from Generation 1 .map((pokemon) -> pokemon.name) // names of Generation 1 Pokemon .filter((name) -> !name.contains("Mega ")) // names of Gen 1 Pokemon without "Mega " in the name .forEach(System.out::println); // void - Print out all the remaining names // Problem 3: Calculate the total sum of the stats our pokemon team List team = new LinkedList(); team.add(pokeMap.get("Pikachu")); team.add(pokeMap.get("Magikarp")); team.add(pokeMap.get("Magikarp")); team.add(pokeMap.get("Lucario")); /* How we would solve this in a cumulative sum fashion? int sum = 0; for (Pokemon pokemon : team) { sum = sum + poke.totalStats; } System.out.println(sum); */ int sum = team .stream() .map((pokemon) -> pokemon.totalStats) .reduce(0, (sum1, totalStats) -> sum1 + totalStats); // Start with a initial value of 0. For every element in our stream, // set it to totalStats and set our cumulative variable sum1 to // sum1 + totalStats System.out.println(sum); } }