126 lines
8.9 KiB
HTML
126 lines
8.9 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>TrueFalseQuiz.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
||
|
.number {color: #6897bb}
|
||
|
.string {color: #6a8759}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
|
||
|
.ST0 {color: #287bde}
|
||
|
.literal {color: #cc7832}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java</td></tr></table>
|
||
|
<pre>
|
||
|
<span class="comment">/*</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||
|
<span class="comment"> */</span>
|
||
|
<span class="literal">package</span> com.calebfontenot.lab5_calebfontenot;
|
||
|
|
||
|
<span class="literal">import</span> java.util.Date;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">class</span> TrueFalseQuiz {
|
||
|
|
||
|
<span class="literal">int</span> currentQuestion;
|
||
|
TrueFalseQuestion[] trueFalseQuestions;
|
||
|
|
||
|
<span class="literal">public</span> TrueFalseQuiz()
|
||
|
{
|
||
|
trueFalseQuestions = <span class="literal">new</span> TrueFalseQuestion[<span class="number">5</span>];
|
||
|
|
||
|
trueFalseQuestions[<span class="number">0</span>]
|
||
|
= <span class="literal">new</span> TrueFalseQuestion(<span class="string">"</span><span class="string">The Pacific Ocean is larger than the Atlantic Ocean.</span><span class="string">"</span>,
|
||
|
<span class="literal">true</span>, <span class="literal">new</span> Date());
|
||
|
|
||
|
trueFalseQuestions[<span class="number">1</span>]
|
||
|
= <span class="literal">new</span> TrueFalseQuestion(<span class="string">"</span><span class="string">The Suez Canal connects the Red Sea and the Indian Ocean.</span><span class="string">"</span>, <span class="literal">false</span>, <span class="literal">new</span> Date());
|
||
|
|
||
|
trueFalseQuestions[<span class="number">2</span>]
|
||
|
= <span class="literal">new</span> TrueFalseQuestion(<span class="string">"</span><span class="string">The source of the nile River is in Egypt.</span><span class="string">"</span>, <span class="literal">false</span>, <span class="literal">new</span> Date());
|
||
|
|
||
|
trueFalseQuestions[<span class="number">3</span>]
|
||
|
= <span class="literal">new</span> TrueFalseQuestion(<span class="string">"</span><span class="string">Lake Baikal is the world</span><span class="literal">\'</span><span class="string">s oldest and deepest freshwater lake.</span><span class="string">"</span>, <span class="literal">true</span>, <span class="literal">new</span> Date());
|
||
|
|
||
|
trueFalseQuestions[<span class="number">4</span>]
|
||
|
= <span class="literal">new</span> TrueFalseQuestion(<span class="string">"</span><span class="string">The Amazon River is the longest river in the Americas.</span><span class="string">"</span>, <span class="literal">true</span>, <span class="literal">new</span> Date());
|
||
|
<span class="literal">this</span>.currentQuestion = <span class="number">0</span>;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> TrueFalseQuiz(String[] questions, <span class="literal">boolean</span>[] trueFalse)
|
||
|
{
|
||
|
<span class="comment">//> Create an array of REFERENCES of size questions.length</span>
|
||
|
<span class="comment">//the references are initializesed to null</span>
|
||
|
trueFalseQuestions = <span class="literal">new</span> TrueFalseQuestion[questions.length];
|
||
|
|
||
|
<span class="comment">//> assign to each reference of the array an object of type TrueFalseQuestion</span>
|
||
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>, j = <span class="number">0</span>; i < questions.length; ++i, ++j) {
|
||
|
trueFalseQuestions[i] = <span class="literal">new</span> TrueFalseQuestion(
|
||
|
questions[i],
|
||
|
trueFalse[j],
|
||
|
<span class="literal">new</span> Date());
|
||
|
<span class="comment">//> set the index of the first question</span>
|
||
|
<span class="literal">this</span>.currentQuestion = <span class="number">0</span>;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Gets</span> <span class="comment">the</span> <span class="comment">current</span> <span class="comment">question</span><span class="comment">.</span> <span class="comment">If</span> <span class="comment">the</span> <span class="comment">current</span> <span class="comment">question</span> <span class="comment">is</span> <span class="comment">the</span> <span class="comment">last</span> <span class="comment">last</span> <span class="comment">question</span> <span class="comment">in</span> <span class="comment">the</span> <span class="comment">quiz</span> <span class="comment">and</span> <span class="comment">we</span> <span class="comment">call</span> <span class="comment">this</span> <span class="comment">method</span> <span class="comment">the</span> <span class="comment">method</span> <span class="comment">will</span> <span class="comment">return</span> <span class="comment">the</span> <span class="comment">first</span> <span class="comment">question</span><span class="comment">.</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">current</span> <span class="comment">question</span><span class="comment">;</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> String nextQuestion()
|
||
|
{
|
||
|
|
||
|
<span class="literal">if</span> (++<span class="literal">this</span>.currentQuestion == <span class="literal">this</span>.trueFalseQuestions.length) {
|
||
|
<span class="literal">this</span>.currentQuestion = <span class="number">0</span>;
|
||
|
}
|
||
|
<span class="literal">this</span>.trueFalseQuestions[<span class="literal">this</span>.currentQuestion].setWhenLastUsed(<span class="literal">new</span> Date());
|
||
|
<span class="literal">return</span> <span class="literal">this</span>.trueFalseQuestions[<span class="literal">this</span>.currentQuestion].getQuestion();
|
||
|
}
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Returns</span> <span class="comment">true</span> <span class="comment">if</span> <span class="comment">the</span> <span class="comment">current</span> <span class="comment">question</span> <span class="comment">is</span> <span class="comment">true</span><span class="comment">.</span>
|
||
|
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">true</span> <span class="comment">if</span> <span class="comment">the</span> <span class="comment">current</span> <span class="comment">question</span> <span class="comment">is</span> <span class="comment">true</span><span class="comment">, </span><span class="comment">false</span> <span class="comment">otherwise</span><span class="comment">.</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">boolean</span> isTrue() {
|
||
|
<span class="literal">return</span> <span class="literal">this</span>.trueFalseQuestions[<span class="literal">this</span>.currentQuestion].isIsTrue();
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">int</span> getCurrentQuestion()
|
||
|
{
|
||
|
<span class="literal">return</span> currentQuestion;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setCurrentQuestion(<span class="literal">int</span> currentQuestion)
|
||
|
{
|
||
|
<span class="literal">this</span>.currentQuestion = currentQuestion;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> TrueFalseQuestion[] getTrueFalseQuestions()
|
||
|
{
|
||
|
<span class="literal">return</span> trueFalseQuestions;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setTrueFalseQuestions(TrueFalseQuestion[] trueFalseQuestions)
|
||
|
{
|
||
|
<span class="literal">this</span>.trueFalseQuestions = trueFalseQuestions;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
</pre></body>
|
||
|
</html>
|