import java.util.ArrayList; public class Annonse { private String annonseTekst; // Kronologisk rekkef?lge p? bud ivaretatt gjennom en liste private ArrayList budListe; public Annonse(String tekst) { annonseTekst = tekst; budListe = new ArrayList<>(); } public void giBud(String navn, int belop) { Bud nyttBud = new Bud(navn, belop); budListe.add(nyttBud); } public int antBud() { return budListe.size(); } public Bud hoyesteBud() { Bud hoyesteBud = null; for (Bud bud : budListe) { if (hoyesteBud == null || bud.hentBud() > hoyesteBud.hentBud()) hoyesteBud = bud; } return hoyesteBud; } public void kraftBud(String navn, int belop, int maks) { Bud hoyesteBud = this.hoyesteBud(); if (belop > hoyesteBud.hentBud()) { giBud(navn, belop); } else { int nyttHoyeste = hoyesteBud.hentBud() + 1; if (maks < nyttHoyeste) return; giBud(navn, nyttHoyeste); } } public void skrivAnnonse() { System.out.println("Annonseinfo: " + annonseTekst + "\nAnnonsen inneholder " + antBud() + " bud"); } public void skrivHoyeste() { Bud bud = hoyesteBud(); if (bud != null) bud.skrivBud(); } }