-
-
Save parzibyte/e35286f399daaec55b0a684f461dc9cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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