Question: Hello, I need some help with my programming assignment to understand why I am having an issue. The assignment is to read a pokemon.csv into

Hello, I need some help with my programming assignment to understand why I am having an issue. The assignment is to read a pokemon.csv into an array list and search the array list for certain pokemon, then display their attributes as listed in the csv. I am NOT looking to copy someone's work. Instead I am looking for an explanation as to why my program is not working properly and the corrective action I should take. Attached is my developed code in java. I am having issue with menu item #2. I can search for a pokemon but when I do it returns nothing. The pokemon.csv file can be found at: https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

Thank you for your help!

Main.java

import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { ArrayList pokedex = new ArrayList<>(); System.out.println("############ POKEDEX MENU ############"); System.out.println("1: Show all pokemon in pokedex"); System.out.println("2: Search for pokemon information by name"); System.out.println("3: Exit program"); System.out.println("Enter choice (1-3): "); System.out.println("========================================"); Scanner user = new Scanner(System.in); int userInput = user.nextInt(); if (userInput == 1) { File pokemonCSV = new File("C:/ClassCode SP2023/CIS211-SP23/pokemon.csv"); Scanner fileScanner = null; try { fileScanner = new Scanner(pokemonCSV); while (fileScanner.hasNextLine()) { String pokemonLine = fileScanner.nextLine(); String[] pokemonSplit = pokemonLine.split(","); String name = pokemonSplit[0]; String type1 = pokemonSplit[1]; String type2 = pokemonSplit[2]; String total = pokemonSplit[3]; String hp = pokemonSplit[4]; String attack = pokemonSplit[5]; String defense = pokemonSplit[6]; String spAttack = pokemonSplit[7]; String spDefense = pokemonSplit[8]; String speed = pokemonSplit[9]; String generation = pokemonSplit[10]; String legendary = pokemonSplit[11]; Pokemon pokemon = new Pokemon(name, type1, type2, total, hp, attack, defense, spAttack, spDefense, speed, generation, legendary); pokedex.add(pokemon); System.out.println(name + ", " + type1 + ", " + type2 + ", " + total + ", " + hp + ", " + attack + ", " + defense + ", " + spAttack + ", " + spDefense + ", " + speed + ", " + generation + ", " + legendary); } } catch (FileNotFoundException e) { System.out.println("Hey you lost your file!"); } } else if (userInput == 2) { Scanner user2 = new Scanner(System.in); System.out.println("Please enter a Pokemon name: "); String pokeName = user2.nextLine(); for (int i = 0; i < pokedex.size(); i++) { Pokemon tempPoke = pokedex.get(i); if (tempPoke.equals(pokeName)) { System.out.println(tempPoke.getName()); } } } else if (userInput == 3) { System.out.println("Gotta Catch 'em all! "); } } }

Pokemon.java

public class Pokemon { private String name; private String type1; private String type2; private int total; private int hp; private int attack; private int defense; private int spAttack; private int spDefense; private int speed; private int generation; private String legendary; public Pokemon(String name, String type1, String type2, int total, int hp, int attack, int defense, int spAttack, int spDefense, int speed, int generation, String legendary) { this.name = name; this.type1 = type1; this.type2 = type2; this.total = total; this.hp = hp; this.attack = attack; this.defense = defense; this.spAttack = spAttack; this.spDefense = spDefense; this.speed = speed; this.generation = generation; this.legendary = legendary; } public Pokemon(String name, String type1, String type2, String total, String hp, String attack, String defense, String spAttack, String spDefense, String speed, String generation, String legendary) { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType1() { return type1; } public void setType1(String type1) { this.type1 = type1; } public String getType2() { return type2; } public void setType2(String type2) { this.type2 = type2; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } public int getHp() { return hp; } public void setHp(int hp) { this.hp = hp; } public int getAttack() { return attack; } public void setAttack(int attack) { this.attack = attack; } public int getDefense() { return defense; } public void setDefense(int defense) { this.defense = defense; } public int getSpAttack() { return spAttack; } public void setSpAttack(int spAttack) { this.spAttack = spAttack; } public int getSpDefense() { return spDefense; } public void setSpDefense(int spDefense) { this.spDefense = spDefense; } public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public int getGeneration() { return generation; } public void setGeneration(int generation) { this.generation = generation; } public String getLegendary() { return legendary; } public void setLegendary(String legendary) { this.legendary = legendary; } @Override public String toString() { return "Pokemon{" + "Name='" + name + ", Type 1='" + type1 + ", Type 2='" + type2 + ", Total=" + total + ", HP=" + hp + ", Attack=" + attack + ", Defense=" + defense + ", Sp. Attack =" + spAttack + ", Sp. Defense=" + spDefense + ", Speed=" + speed + ", Generation=" + generation + ", Legendary=" + legendary; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!