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); } // 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 // 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 List team = new LinkedList(); team.add(pokeMap.get("Pikachu")); team.add(pokeMap.get("Magikarp")); team.add(pokeMap.get("Magikarp")); team.add(pokeMap.get("Lucario")); // Calculate the total sum of the stats of our pokemon team /* 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); } }