I have a problem that I can not solve with a java loop for a class exercise. I need to make a program that asks 10 questions of random multiplication tables. At the end of the 10 questions, you have to show me the questions that were right the first time. In case a question is not answered to the first one, it should show the table of the failed number and then reformulate the question.
The mistake I have is that within for
of the 10 questions I have a if -else
for the correct questions and within the else the do-while
to reformulate the questions.
The problem is this: when I fail the question, the program reformulates it as it should do but if I enter the correct answer, the loop do-while
I close the for
and stop asking questions.
I leave the code here.
for (int i=1; i<=10; i++) {
Tablas operacion=new Tablas();
int pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
if (pregunta == operacion.resultado()) {
Tablas.comprobadorPreguntas(true);
}
else {
do {
String salida="";
for (i=1; i<=10; i++) {
salida+=operacion.getMultiplicando() + "x"+i+"=" + (operacion.getMultiplicando() * i) + "\n";
}
JOptionPane.showMessageDialog(null, salida);
pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
} while(pregunta != operacion.resultado());
Tablas.comprobadorPreguntas(false);
}
}
JOptionPane.showMessageDialog( null, "Preguntas acertadas a la primera: "+Tablas.getContador());
Here I also leave the pastebin with the classes of the program and the methods. I would also appreciate suggestions to improve the code.
Program > link
Methods > link
Thank you very much