import java.util.Scanner; import java.util.ArrayList; import java.io.File; import java.io.FileNotFoundException; public class Pokedex { private ArrayList dex; private int ant; public Pokedex(){ dex = new ArrayList(); ant = 0; } public void settInn(Pokemon p) { dex.add(p); ant++; } public void registrer(String filnavn) { File pokemonListe = new File(filnavn); Scanner listeScan = null; // initialiserer som null try { listeScan = new Scanner(pokemonListe); } catch (FileNotFoundException e) { System.out.println("PokemonListe ikke funnet! Har du mistet den?"); } while(listeScan.hasNextLine()) { String data[] = listeScan.nextLine().split(";"); String art = data[0]; int hp = Integer.parseInt(data[1]); int angrep = Integer.parseInt(data[2]); switch (art) { case "squirtle": dex.add(new Squirtle(hp, angrep)); break; case "charmander": dex.add(new Charmander(hp, angrep)); break; case "charmeleon": dex.add(new Charmeleon(hp, angrep)); break; case "bulbasaur": dex.add(new Bulbasaur(hp, angrep)); break; default: System.out.println("Feil i fil-format"); } ant++; } } public void visFlammeTyper() { System.out.println("\n----- FlammeTyper -----"); for (Pokemon p : dex) { if (p instanceof FlammeType) { p.info(); } } } public void visVannTyper() { System.out.println("\n----- VannTyper -----"); for (Pokemon p : dex) { if (p instanceof VannType) { p.info(); } } } public void visGressTyper() { System.out.println("\n----- GressTyper -----"); for (Pokemon p : dex) { if (p instanceof GressType) { p.info(); } } } public void visAlle() { System.out.println("\n----- Alle Pokemon -----"); for (Pokemon p : dex) { p.info(); } } public int hentAnt() { return ant; } }