import java.util.Scanner; // Disse trenger vi i tillegg for å lese filer import java.io.File; import java.io.FileNotFoundException; // To ulike collections import java.util.ArrayList; import java.util.HashMap; public class Hovedprogram { public static void main(String[] args) { //Hund[] hunder = new Hund[3]; //Array ArrayList hunder = new ArrayList<>(); //ArrayList HashMap hunderHash = new HashMap<>(); // Dersom vi har sendt med et filnavn if (args.length == 1) { //Vi må legge inn en try-catch for dersom filen ikke finnes. try { String filnavn = args[0]; File fil = new File(filnavn); // Opprette File-objekt Scanner filScan = new Scanner(fil); int i = 0; while (filScan.hasNextLine()) { String[] data = filScan.nextLine().split(","); // Dele opp input String navn = data[0]; int alder = Integer.parseInt(data[1]); // Omgjøring til int //hunder[i] = new Hund(navn, alder); // Array hunder.add(new Hund(navn, alder)); i++; } filScan.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { Scanner inputScan = new Scanner(System.in); System.out.println("Angi antall hunder:"); int antallHunder = Integer.parseInt(inputScan.nextLine()); int i = 0; while (i < antallHunder) { System.out.println("\nAngi navn paa hund nr " + i); String navn = inputScan.nextLine(); System.out.println("Angi alder paa hund nr " + i); int alder = inputScan.nextInt(); // Denne er litt skummel, hvorfor? inputScan.nextLine(); hunderHash.put(navn, new Hund(navn, alder)); // Putt i HashMap i++; } inputScan.close(); } //Vi antar at listen er full for (Hund hund : hunder) { hund.bjeff(); } //for (Hund hund : hunderHash.values()) { // hund.bjeff(); //} } }