Question
Create a FOR loop to go over all the questions, one by one. For each question: o Create a String variable and concatenate the questions
Create a FOR loop to go over all the questions, one by one. For each question: o Create a String variable and concatenate the questions and the multiple choices. o To have new lines as shown in the figure above, concatenate after each possible answer in the multiple
choice. o Use this concatenated string as input in your JOptionPane.showInputDialog() method.
-
Collect the answer from the JOptionPane dialog box (you will need to convert the returning value from String to integer).
-
Compare this value with the actual correct answer that you got from the text file (the integer array of correct answers that you have created.
-
Create an integer variable to keep track of how many answers were correct
I need help writing code to have a single dialog box with a question and the 5 possible answers. I will provide my code, please help me modify, or add to it to make this happen. I currently get multiple boxes
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import javax.swing.JOptionPane;
public class JavaApplication11 {
public static void main(String[] args) throws FileNotFoundException { //reading the exam questions from a text file String filePath = "/Users/owner/Desktop/Test.txt"; File file = new File(filePath); Scanner filePointer = new Scanner(file); String examTopic = filePointer.nextLine(); double minPercentNeeded = Double.parseDouble(filePointer.nextLine()); System.out.println(minPercentNeeded); String [] questions = new String [10]; String [] [] McNumberAndAns = new String [10] [5]; int [] numberCorrectAns = new int[10]; int questionIndex = 0; //reading the exam questions and storing answers and questions into arrays while(filePointer.hasNextLine()) { questions [questionIndex] = filePointer.nextLine(); McNumberAndAns [questionIndex]= filePointer.nextLine().split("#",5); String temp= filePointer.nextLine(); System.out.println(temp); numberCorrectAns [questionIndex]= Integer.parseInt(temp); questionIndex++; } filePointer.close(); for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started