/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TakeQuiz.java |
package com.calebfontenot.lab5_calebfontenot;
import java.util.Scanner;
@author
public class TakeQuiz {
public static void takeQuiz(TrueFalseQuiz quiz) {
Scanner scan = new Scanner(System.in);
String s = "";
do
{
System.out.println("q\\Q to quit");
System.out.println("n\\N next question");
s = scan.next();
if (s.compareToIgnoreCase("q") == 0)
{
break;
}
else if ("n".compareToIgnoreCase(s) == 0)
{
System.out.println("+++++++++++" + quiz.nextQuestion() + "+++++++++++");
String answer = "";
do
{
System.out.println("\tt\\T for true");
System.out.println("\tf\\F for false");
answer = scan.next();
if ("t".compareToIgnoreCase(answer) != 0 && "f".compareToIgnoreCase(answer) != 0)
{
System.out.println("\t\tf INVALID CHOICE");
}
}
while ("t".compareToIgnoreCase(answer) != 0 && "f".compareToIgnoreCase(answer) != 0);
boolean convertAnswerToBoolean = "t".compareToIgnoreCase(answer) == 0;
System.out.println(quiz.isTrue() == convertAnswerToBoolean
? "\t\t---------correct"
: "\t\t---------incorrect");
}
else
{
System.out.println("Invalid choice. Try again");
}
}
while (true);
}
public static void main(String[] args)
{
TrueFalseQuiz quiz = new TrueFalseQuiz();
TakeQuiz.takeQuiz(quiz);
for (int i = 0; i < quiz.getTrueFalseQuestions().length; ++i) {
System.out.println(quiz.getTrueFalseQuestions()[i].getWhenLastUsed());
}
}
}