import java.io.IOException; import java.util.List; public class TekstController { private static final int ANTALL = 9; private BigramModel model; private TekstView view; private boolean running = false; public TekstController(BigramModel model, TekstView view) { this.model = model; this.view = view; } public int start(String filNavn) { view.velkomst(); try { model.les(filNavn); } catch (IOException e) { view.skrivFeil("Filen " + filNavn + " feilet"); return 1; } if (model.erTom()) { view.skrivFeil("Filen " + filNavn + " er tom"); return 2; } running = true; return run(); } public int run() { while (running) { view.visOrd(model.hentOrd()); List ordliste = model.hentNesteOrdListe(ANTALL); if (ordliste != null) { view.visOrdValg(ordliste); int valg = view.hentBrukerValg(); if (valg > 0 && valg <= ordliste.size()) { model.leggTilSetning(ordliste.get(valg - 1)); } else { running = false; } } view.skrivSetning(model.hentSetning()); } return 0; } }