import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; class MainHund2{ public static void main(String[] args) { Scanner filScanner = null; try{ File fil = new File("hunde.txt"); filScanner = new Scanner(fil); }catch(FileNotFoundException exception){ System.out.println(exception.getMessage()); System.exit(1); } Hund[] alleHunder = new Hund[filScanner.nextInt()]; int nesteLedige = 0; filScanner.nextLine(); filScanner.nextLine(); while(filScanner.hasNextLine()){ String navn = filScanner.next(); int alder = filScanner.nextInt(); String favorittgodis = filScanner.next(); filScanner.nextLine(); Hund hund = new Hund(navn, alder); hund.settFavorittGodis(favorittgodis); //alleHunder[nesteLedige++]; er samme som de to neste linjene alleHunder[nesteLedige] = hund; nesteLedige++; } for(Hund hund : alleHunder){ if(hund != null){ hund.skrivUt(); } } for(int i = 0; i < alleHunder.length -1; i++){ if (alleHunder[i] != null){ alleHunder[i].skrivUt(); } } } }