Question: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class QuizApp { public static void main(String[] args) throws FileNotFoundException { //reading the exam questions from a text
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class QuizApp {
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 = filePointer.nextDouble();
while(filereader.hasNext()) { String [] questions = new String []; } } }
I need to modify this code to fulfill the following requirements
-
a) Use your Scanner object to get the first line containing the exam topic (What kind of variable type should it be? Integer, double, string???). Create a variable to hold this info.
-
b) Use your Scanner object to get the minimum percentage of correct answer to pass the exam. Again, what type of variable should you create to store this info?
-
c) For the set of 10 questions, use a WHILE loop. What would be the WHILE loop condition to keep going?
-
d) There are two ways of reading the questions and performing the exam:
-
1) As your program reads a given question, it presents the question to the student and after the student answer the question, your program reads the other question from the file and so on. This way your program does not need to store all the questions in the memory, just the current one.
-
2) Your program reads all the questions at once and place them into arrays and then after finish reading all of them it starts the exam per say.
Question: what are the pros and cons of using each approach?
You are required to use the second approach, i.e., read all the questions first and then start the exam. To do so, your program shall create the following arrays to hold all the data read from the text file:
-
a) 1-dimension String array, String[], to hold the questions (10 questions).
-
b) 2-dimension String array, String[][], to hold the multiple choice answers, where the first index of the
array is the question number and the second index is the specific answer (from 5 answers of the
multiple choice).
-
c) A 1-Dimension integer array, int[], containing the numbers of the correct answers.
-
The text file shall have the following structure:
-
a) First line contains the Exam topic.
-
b) Second line is the minimum percentage of correct answers to pass the exam.
-
c) The rest of the file contains up to 10 sets of questions (it may vary for other exams) in the following structure:
First line of a given question set: The Question itself. Second line of a given question set: The multiple choices separated by the symbol #. Third line of a given question set: the number of the correct answer of this set.
-
d) Use the contents of Appendix A at the end of this document as the basis for your exam.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
