my program is supposed to take questions from a file and print them and the answers. then the user is supposed to answer them and if they get it wrong the program is supposed to deduct points. each question is worth 5 and getting it wrong makes you lose 2. But when you get it wrong its supposed to keep asking you the question not just go on to the next how can i fix this? And show the user how many points they have left.
import java.util.Scanner;
public class HW21 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
HWData hd = new HWData();
int currentScore = 5;
int numberOfQuestions = hd.getNumberOfQuestions();
for (int questionIndex=0; questionIndex<numberOfQuestions; ++questionIndex) {
System.out.println(hd.getQuestion(questionIndex));
System.out.println();
System.out.println("1. " + hd.getAnswer1(questionIndex));
System.out.println();
System.out.println("2. " + hd.getAnswer2(questionIndex));
System.out.println();
System.out.println("3. " + hd.getAnswer3(questionIndex));
System.out.println();
System.out.println("4. " + hd.getAnswer4(questionIndex));
int answer = input.nextInt();
if (answer == hd.getCorrect(questionIndex)) {
System.out.println(" Great Job! You got the right answer!");
}
else {
System.out.println(" You got the answer wrong.");
currentScore -= 2;
}
}
input.close();
System.out.println("Final score: " + currentScore);
}
}