/*
 * 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.Date;

/**
 *
 * @author caleb
 */
public class TrueFalseQuiz {

    int currentQuestion;
    TrueFalseQuestion[] trueFalseQuestions;

    public TrueFalseQuiz()
    {
        trueFalseQuestions = new TrueFalseQuestion[5];

        trueFalseQuestions[0]
                = new TrueFalseQuestion("The Pacific Ocean is larger than the Atlantic Ocean.",
                        true, new Date());

        trueFalseQuestions[1]
                = new TrueFalseQuestion("The Suez Canal connects the Red Sea and the Indian Ocean.", false, new Date());

        trueFalseQuestions[2]
                = new TrueFalseQuestion("The source of the nile River is in Egypt.", false, new Date());

        trueFalseQuestions[3]
                = new TrueFalseQuestion("Lake Baikal is the world\'s oldest and deepest freshwater lake.", true, new Date());

        trueFalseQuestions[4]
                = new TrueFalseQuestion("The Amazon River is the longest river in the Americas.", true, new Date());
        this.currentQuestion = 0;
    }

    public TrueFalseQuiz(String[] questions, boolean[] trueFalse)
    {
        //> Create an array of REFERENCES of size questions.length
        //the references are initializesed to null
        trueFalseQuestions = new TrueFalseQuestion[questions.length];

        //> assign to each reference of the array an object of type TrueFalseQuestion
        for (int i = 0, j = 0; i < questions.length; ++i, ++j) {
            trueFalseQuestions[i] = new TrueFalseQuestion(
                    questions[i],
                    trueFalse[j],
                    new Date());
            //> set the index of the first question
            this.currentQuestion = 0;
        }
    }

    /**
     * Gets the current question. If the current question is the last last question in the quiz and we call this method the method will return the first question.
     *
     * @return current question;
     */
    public String nextQuestion()
    {
        
        if (++this.currentQuestion == this.trueFalseQuestions.length) {
            this.currentQuestion = 0;
        }
        this.trueFalseQuestions[this.currentQuestion].setWhenLastUsed(new Date());
        return this.trueFalseQuestions[this.currentQuestion].getQuestion();
    }
    /**
     * Returns true if the current question is true.
     * @return true if the current question is true, false otherwise. 
     */
    public boolean isTrue() {
        return this.trueFalseQuestions[this.currentQuestion].isIsTrue();
    }

    public int getCurrentQuestion()
    {
        return currentQuestion;
    }

    public void setCurrentQuestion(int currentQuestion)
    {
        this.currentQuestion = currentQuestion;
    }

    public TrueFalseQuestion[] getTrueFalseQuestions()
    {
        return trueFalseQuestions;
    }

    public void setTrueFalseQuestions(TrueFalseQuestion[] trueFalseQuestions)
    {
        this.trueFalseQuestions = trueFalseQuestions;
    }

}
