public final class RegistroVoti {
    private final String studente;
    private final int[] voti;

    public RegistroVoti(String studente, int[] voti) {
        if (studente == null || studente.isBlank()) {
            throw new IllegalArgumentException("studente mancante");
        }
        if (voti == null || voti.length == 0) {
            throw new IllegalArgumentException("serve almeno un voto");
        }
        for (int voto : voti) {
            if (voto < 0 || voto > 30) {
                throw new IllegalArgumentException("voto fuori intervallo");
            }
        }
        this.studente = studente;
        this.voti = voti.clone();
    }

    public RegistroVoti(String studente, int voto) {
        if (voto < 0 || voto > 30) {
            throw new IllegalArgumentException("voto fuori intervallo");
        }
        this(studente, new int[] {voto});
    }

    public String studente() {
        return studente;
    }

    public int[] voti() {
        return voti.clone();
    }

    public double media() {
        int somma = 0;
        for (int voto : voti) {
            somma += voto;
        }
        return (double) somma / voti.length;
    }

    public static void main(String[] args) {
        int[] originali = {24, 27, 30};
        RegistroVoti registro = new RegistroVoti("Ada", originali);
        originali[0] = 0;
        int[] ricevuti = registro.voti();
        ricevuti[1] = 0;
        System.out.println(registro.studente() + ": " + registro.media());
    }
}
