-
-
Save parzibyte/f4fb43be1a826328e5e3459ccdb764a7 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 Pregunta { | |
private final String pregunta; | |
private final List<Respuesta> respuestas; | |
// Nota: si crees que agregarás más respuestas, amplía las letras | |
private static final String letras = "abcdefghijklmnñopqrstuvwxyz"; | |
public Pregunta(String pregunta, List<Respuesta> respuestas) { | |
this.pregunta = pregunta; | |
this.respuestas = respuestas; | |
} | |
public Pregunta(String pregunta) { | |
this.pregunta = pregunta; | |
this.respuestas = new ArrayList<>(); | |
} | |
public void agregarRespuesta(Respuesta r) { | |
this.respuestas.add(r); | |
} | |
public boolean respuestaCorrecta(char respuesta) { | |
int indice = letras.indexOf(respuesta); | |
if (indice == -1) { | |
return false; | |
} | |
return this.respuestas.get(indice).esCorrecta; | |
} | |
public boolean preguntar(int numero) { | |
System.out.println(numero + ". " + this.pregunta); | |
int indice = 0; | |
for (Respuesta r : this.respuestas) { | |
System.out.printf("%c) %s\n", letras.charAt(indice), r.respuesta); | |
indice++; | |
} | |
System.out.println("Elige: "); | |
Scanner sc = new Scanner(System.in); | |
char respuesta = sc.nextLine().charAt(0); | |
return this.respuestaCorrecta(respuesta); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment