Running into issues with lining up My true and false answers with the line the question, comes from. The objective is to randomly ask a question and the correct answer should line up with the same line the question comes from.
public static void main(String[] args) throws IOException
{
int question=0;
int i=0;
final int SIZE = 125;
int count=0;
int randomNum=0;
String input="";
Random randNum = new Random();
String[] testBank = new String[SIZE];
Scanner keyboard = new Scanner(System.in);
File thequestion= new File("/Users/BruceNguyen/Documents/Cosc236/Labs"
+ "/Final Project/TestBank.txt");
Scanner theQuestion = new Scanner(thequestion);
File answer = new File("/Users/BruceNguyen/Documents/Cosc236/Labs"
+ "/Final Project/Answers.txt");
Scanner theAnswer = new Scanner(answer);
//To acquire the questions from the TestBank.txt into the testbank array
while(theQuestion.hasNext() && i<testBank.length)
{
testBank[i]=theQuestion.nextLine();
i++;
}
//Initialize the question for 10 times randomly
while(count<10)
{
randomNum = randNum.nextInt(SIZE);
System.out.println(testBank[randomNum]);
System.out.println("True or False ?");
//input confirmation
while(!input.equalsIgnoreCase("True") && !input.equalsIgnoreCase("False"))
{
input = keyboard.nextLine();
}
//to authenticate the input
if(input.equalsIgnoreCase(theAnswer.nextLine()))
{
question++;
}
count++;
input="";
}
System.out.printf("You got %d question right.", question);
theQuestion.close();
theAnswer.close();
}
}
Aucun commentaire:
Enregistrer un commentaire