import java.io.File; import java.util.Scanner; import java.util.HashMap; class StudentSystem { private Emne[] emner; private HashMap studenter = new HashMap(); private String filnavn; private static int idTeller = 0; public StudentSystem(Emne[] emner, String filnavn) { this.emner = emner; this.filnavn = filnavn; } public void lesFraFil() { Scanner sc = null; try { File fil = new File(filnavn); sc = new Scanner(fil); } catch (Exception e) { System.out.println("Fant ikke filen"); } while (sc.hasNextLine()){ String navn = sc.nextLine().trim(); int id = idTeller; Student student = new Student(navn, id); studenter.put(id, student); idTeller++; } } public void skrivUtStudenter(){ for (Integer id : studenter.keySet()) { Student student = studenter.get(id); System.out.println(id + ": " + student.hentNavn()); } } }