Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 15, 2021 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e35286f399daaec55b0a684f461dc9cc to your computer and use it in GitHub Desktop.
Save parzibyte/e35286f399daaec55b0a684f461dc9cc to your computer and use it in GitHub Desktop.
class Cuestionario {
private final List<Pregunta> preguntas;
private int aciertos;
private int errores;// ¿Alguien sabe el antónimo de acierto en este contexto? yo no
public Cuestionario() {
this.preguntas = new ArrayList<>();
}
public void agregarPregunta(Pregunta p) {
this.preguntas.add(p);
}
public void preguntar() {
int numero = 1;
for (Pregunta p : this.preguntas) {
boolean acierta = p.preguntar(numero);
numero++;
if (acierta) {
System.out.println("Correcto");
this.aciertos++;
} else {
System.out.println("Incorrecto");
this.errores++;
}
}
}
public void imprimirResultados() {
int total = this.preguntas.size();
double porcentajeAciertos = (100 * (double) this.aciertos) / total;
double porcentajeErrores = (100 * (double) this.errores) / total;
System.out.printf("Total de preguntas: %d\nAciertos: %d (%.2f %%)\nErrores: %d (%.2f %%)", total, this.aciertos, porcentajeAciertos, this.errores, porcentajeErrores);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment