Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please refactor/change code to have the same usage. make it different. import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class PokedexDriverCSV { public static

Please refactor/change code to have the same usage.

make it different.

import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class PokedexDriverCSV { public static void main(String[] args) throws FileNotFoundException { var scanner = new Scanner(System.in); ArrayList pokemonArrayList; pokemonArrayList = new ArrayList<>(); File pokemoncsvfile; pokemoncsvfile = new File(""); Scanner csv; csv = new Scanner(pokemoncsvfile); int x ; boolean z =true; while(csv.hasNextLine()){ String Line; Line = csv.nextLine(); String[] Pokesplit = Line.split(","); int Id; Id = Integer.parseInt(Pokesplit[0]); String Name; Name = Pokesplit[1]; String Type1; Type1 = Pokesplit[2]; String Type2; Type2 = Pokesplit[3]; int Total; Total = Integer.parseInt(Pokesplit[4]); int Hp; Hp = Integer.parseInt ( Pokesplit[ 5 ] ); int Attack; Attack = Integer.parseInt ( Pokesplit[ 6 ] ); int Defense; Defense = Integer.parseInt ( Pokesplit[ 7 ] ); int SpAtk; SpAtk = Integer.parseInt ( Pokesplit[ 8 ] ); int SpDef; SpDef = Integer.parseInt ( Pokesplit[ 9 ] ); int Speed; Speed = Integer.parseInt ( Pokesplit[ 10 ] ); int Generation = Integer.parseInt ( Pokesplit[ 11 ] ); String Legendary; Legendary = Pokesplit[12]; Pokemon Pokemon; Pokemon = new Pokemon( Id, Name, Type1, Type2, Total, Hp, Attack, Defense, SpAtk, SpDef, Speed, Generation, Legendary); pokemonArrayList.add(Pokemon); } if (z) { for (String s : Arrays.asList ( " Pokedex Driver", " 1 : View Pokedex", " 2: Search Pokemon", "3 : EXIT ", "Choose option 1-3 : " )) { System.out.println ( s ); } x = scanner.nextInt (); if (x == 1) for (Pokemon pokemon : pokemonArrayList) { System.out.println ( pokemon ); } if (x == 2) { String nickname; Scanner bcanner = new Scanner ( System.in ); try { System.out.println ( "Search Pokemon" ); nickname = bcanner.nextLine (); } finally { bcanner.close (); } for (Pokemon pokemon : pokemonArrayList) { if (pokemon.getName ().equals ( nickname )) { System.out.println ( pokemon ); } } } if (x == 3) { System.out.println ( "GoodBye!" ); z = false; } while (z) { for (String s : Arrays.asList ( " Pokedex Driver", " 1 : View Pokedex", " 2: Search Pokemon", "3 : EXIT ", " Enter the number below" )) { System.out.println ( s ); } x = scanner.nextInt (); if (x == 1) for (Pokemon pokemon : pokemonArrayList) { System.out.println ( pokemon ); } if (x == 2) { String name; Scanner scan = new Scanner ( System.in ); try { System.out.println ( " Enter the name of pokemon" ); name = scan.nextLine (); } finally { scan.close (); } for (Pokemon pokemon : pokemonArrayList) { if (pokemon.getName ().equals ( name )) { System.out.println ( pokemon ); } } } if (x == 3) { System.out.println ( "GoodBye!" ); z = false; } } }}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions