ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html

97 lines
6.5 KiB
HTML
Raw Normal View History

2023-01-26 12:27:18 -06:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TakeQuiz.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
.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/TakeQuiz.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java 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.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> TakeQuiz {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> takeQuiz(TrueFalseQuiz quiz) {
<span class="comment">//&gt;Create a scanner for reading</span>
Scanner scan = <span class="literal">new</span> Scanner(System.in);
String s = <span class="string">&quot;&quot;</span>;
<span class="comment">//&gt;do forever</span>
<span class="literal">do</span>
{
System.out.println(<span class="string">&quot;</span><span class="string">q</span><span class="literal">\\</span><span class="string">Q to quit</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="string">n</span><span class="literal">\\</span><span class="string">N next question</span><span class="string">&quot;</span>);
s = scan.next();
<span class="literal">if</span> (s.compareToIgnoreCase(<span class="string">&quot;</span><span class="string">q</span><span class="string">&quot;</span>) == <span class="number">0</span>)
{
<span class="literal">break</span>;
}
<span class="literal">else</span> <span class="literal">if</span> (<span class="string">&quot;</span><span class="string">n</span><span class="string">&quot;</span>.compareToIgnoreCase(s) == <span class="number">0</span>)
{
System.out.println(<span class="string">&quot;</span><span class="string">+++++++++++</span><span class="string">&quot;</span> + quiz.nextQuestion() + <span class="string">&quot;</span><span class="string">+++++++++++</span><span class="string">&quot;</span>);
String answer = <span class="string">&quot;&quot;</span>;
<span class="literal">do</span>
{
System.out.println(<span class="string">&quot;</span><span class="literal">\t</span><span class="string">t</span><span class="literal">\\</span><span class="string">T for true</span><span class="string">&quot;</span>);
System.out.println(<span class="string">&quot;</span><span class="literal">\t</span><span class="string">f</span><span class="literal">\\</span><span class="string">F for false</span><span class="string">&quot;</span>);
answer = scan.next();
<span class="literal">if</span> (<span class="string">&quot;</span><span class="string">t</span><span class="string">&quot;</span>.compareToIgnoreCase(answer) != <span class="number">0</span> &amp;&amp; <span class="string">&quot;</span><span class="string">f</span><span class="string">&quot;</span>.compareToIgnoreCase(answer) != <span class="number">0</span>)
{
System.out.println(<span class="string">&quot;</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">f INVALID CHOICE</span><span class="string">&quot;</span>);
}
}
<span class="literal">while</span> (<span class="string">&quot;</span><span class="string">t</span><span class="string">&quot;</span>.compareToIgnoreCase(answer) != <span class="number">0</span> &amp;&amp; <span class="string">&quot;</span><span class="string">f</span><span class="string">&quot;</span>.compareToIgnoreCase(answer) != <span class="number">0</span>);
<span class="literal">boolean</span> convertAnswerToBoolean = <span class="string">&quot;</span><span class="string">t</span><span class="string">&quot;</span>.compareToIgnoreCase(answer) == <span class="number">0</span>;
System.out.println(quiz.isTrue() == convertAnswerToBoolean
? <span class="string">&quot;</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">---------correct</span><span class="string">&quot;</span>
: <span class="string">&quot;</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">---------incorrect</span><span class="string">&quot;</span>);
}
<span class="literal">else</span>
{
System.out.println(<span class="string">&quot;</span><span class="string">Invalid choice. Try again</span><span class="string">&quot;</span>);
}
}
<span class="literal">while</span> (<span class="literal">true</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
TrueFalseQuiz quiz = <span class="literal">new</span> TrueFalseQuiz();
TakeQuiz.takeQuiz(quiz);
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; quiz.getTrueFalseQuestions().length; ++i) {
System.out.println(quiz.getTrueFalseQuestions()[i].getWhenLastUsed());
}
}
}
</pre></body>
</html>