import java.util.Scanner; import java.io.File; public class BibliotekArray { private Bok[] bibliotek = new Bok[100]; private int i = 0; /* Metode som leser inn fra fil */ public void lesFil(String filnavn) throws Exception { Scanner in = new Scanner(new File(filnavn)); while(in.hasNextLine()) { String tittel = in.nextLine(); int nummer = Integer.parseInt(in.nextLine()); leggTilBok(tittel, nummer); } } /* Metode som legger inn en ny bok i biblioteket */ public void leggTilBok(String tittel, int nummer) { Bok b = new Bok(tittel, nummer); bibliotek[i] = b; i++; } /* Finner og returnerer en bok basert p? tittel */ public Bok finnBokMedTittel(String tittel) { for(int j = 0; j < i; j++) { if(bibliotek[j].toString().equals(tittel)) { return bibliotek[j]; } } return null; } /* Finner og returnerer bok basert p? nummer */ public Bok finnBokMedNummer(int nummer) { for(int j = 0; j < i; j++) { if(bibliotek[j].hentNr() == nummer) { return bibliotek[j]; } } return null; } /* Printer ut informasjon om alle bokene i biblioteket */ public void printInformasjon() { for(int j = 0; j < i; j++) { System.out.println("Bokens tittel: " + bibliotek[j].toString()); System.out.println("Bokens unike nummer: " + bibliotek[j].hentNr()); System.out.println(""); } } }