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 its 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.stream() .map((pokemon) -> pokemon.name) .forEach(System.out::println); // Problem 2: Print out the names of only the pokemon from the first generation pokedex.stream() // Stream .filter((pokemon) -> pokemon.generation == 1) // Stream .map((pokemon) -> pokemon.name) // Stream .filter((pokemon) -> !pokemon.contains("Mega ")) .forEach(System.out::println); // Problem 3: Calculate the total sum of the stats our pokemon team List team = new LinkedList(); team.add(pokeMap.get("Feebas")); team.add(pokeMap.get("Bulbasaur")); team.add(pokeMap.get("Weedle")); team.add(pokeMap.get("Weedle")); team.add(pokeMap.get("Blastoise")); /* int sum = 0; // Initial value for (Pokemon poke : team) { sum = sum + poke.totalStats; // How to update our cumulative variable } */ int totalSum = team.stream() .map((pokemon) -> pokemon.totalStats) .reduce(0, (sum, stats) -> sum + stats); System.out.println(totalSum); } }