Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//I want to replace the Next Question button when it is out of questions. There

ID: 3740940 • Letter: #

Question

//I want to replace the Next Question button when it is out of questions. There are //7 questions in total in the ga array. I want to replace it with the Results button //to display the end result of the game. Please help. Thanks! public HBox getNextQuestionPane() btnNext new Button( "Next Question"); DropShadow shadownew DropShadow btnNext.setTranslateX(-40); btnNext.setTranslateY(-20); btnNext.setEffect(shadow); btnNext.setOnAction( (ActionEvent e) -> { currentQuestion++; new QAPane(FileUtils.getQAArray[currentQuestion]);// display next question in borderPane //This does not work if (currentQuestion6) { Button results new Button(" Results"); results.setOnAction((ActionEvent a) - { Alert alert -new Alert(AlertType.INFORMATION); alert.setTitle(" Results"); alert.setHeaderText( "Your game results"); alert.setContentText("The total score is: "); new HBox(results); btnNext.setDisable(true); return new HBox(btnNext);

Explanation / Answer

I am explaining the logic which can be applied:

Declare a static variable named question_count and initialise it to 0(Well, a static variable automatically initialises to zero.)

Further, modify your code in the following ways:

Increase the count of the question_count variable by 1 in the button click event each time. And in the code, check when the value of the question_count reaches 7 disable the next button or set its visibility to false.

Create a new instance of a button dynamically and set its text to result. In the click event of the results button put the code to display the end result of the game.

This can be done in another way as well. Instead of creating a button dynamically, create the two separate buttons at compile time only. Set the visibility of the result button false until the value of the question_count reaches 7. When it happens, set its visibility to true and that of the next button to false. And in the click event of the results button,put your desired code.