/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab5_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class TakeQuiz {
    public static void takeQuiz(TrueFalseQuiz quiz) {
        //>Create a scanner for reading
        Scanner scan = new Scanner(System.in);
        String s = "";

        //>do forever
        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());
        }
    }
}
