lab2
This commit is contained in:
parent
fe3eb30a9c
commit
601b7ebc0c
123
Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html
Normal file
123
Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html
Normal file
@ -0,0 +1,123 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>QuadraticEquation.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}
|
||||
.ST2 {color: #9876aa}
|
||||
.ST3 {color: #ffc66d}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST5 {color: #ffc66d; font-family: monospace; font-style: italic}
|
||||
.ST6 {color: #9876aa; font-family: monospace; font-style: italic}
|
||||
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
.ST4 {font-family: monospace; font-style: italic}
|
||||
-->
|
||||
</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/QuadraticEquation.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="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> QuadraticEquation {
|
||||
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">a</span>;
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">b</span>;
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">c</span>;
|
||||
|
||||
<span class="literal">public</span> QuadraticEquation(<span class="literal">double</span> a, <span class="literal">double</span> b, <span class="literal">double</span> c)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST2">a</span> = a;
|
||||
<span class="literal">this</span>.<span class="ST2">b</span> = b;
|
||||
<span class="literal">this</span>.<span class="ST2">c</span> = c;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getDiscriminant</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getRoot1</span>()
|
||||
{
|
||||
<span class="literal">if</span> (getDiscriminant() < <span class="number">0</span>) {
|
||||
<span class="literal">return</span> -<span class="number">88888888</span>;
|
||||
}
|
||||
<span class="literal">return</span> (<span class="ST2">b</span> + Math.<span class="ST4">sqrt</span>(<span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>)) / (<span class="number">2</span> * <span class="ST2">a</span>);
|
||||
}
|
||||
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getRoot2</span>()
|
||||
{
|
||||
<span class="literal">if</span> (getDiscriminant() < <span class="number">0</span>) {
|
||||
<span class="literal">return</span> -<span class="number">88888888</span>;
|
||||
}
|
||||
<span class="literal">return</span> (-<span class="ST2">b</span> + Math.<span class="ST4">sqrt</span>(<span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>)) / (<span class="number">2</span> * <span class="ST2">a</span>);
|
||||
|
||||
<span class="comment">//return getDiscriminant() < 0 ? 0</span>
|
||||
<span class="comment">// : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);</span>
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> String <span class="ST3">toString</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">QuadraticEquation{</span><span class="string">"</span> + <span class="string">"</span><span class="string">a=</span><span class="string">"</span> + <span class="ST2">a</span> + <span class="string">"</span><span class="string">, b=</span><span class="string">"</span> + <span class="ST2">b</span> + <span class="string">"</span><span class="string">, c=</span><span class="string">"</span> + <span class="ST2">c</span> + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">b</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">b</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getB</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST2">b</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">c</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">c</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getC</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST2">c</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">a</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">a</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getA</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST2">a</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args)
|
||||
{
|
||||
QuadraticEquation eq1 = <span class="literal">new</span> QuadraticEquation(<span class="number">1</span>, -<span class="number">4</span>, <span class="number">4</span>);
|
||||
System.<span class="ST6">out</span>.println(eq1);
|
||||
System.<span class="ST6">out</span>.println(eq1.getRoot1());
|
||||
System.<span class="ST6">out</span>.println(eq1.getRoot2());
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
96
Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html
Normal file
96
Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html
Normal file
@ -0,0 +1,96 @@
|
||||
<!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">//>Create a scanner for reading</span>
|
||||
Scanner scan = <span class="literal">new</span> Scanner(System.in);
|
||||
String s = <span class="string">""</span>;
|
||||
|
||||
<span class="comment">//>do forever</span>
|
||||
<span class="literal">do</span>
|
||||
{
|
||||
|
||||
System.out.println(<span class="string">"</span><span class="string">q</span><span class="literal">\\</span><span class="string">Q to quit</span><span class="string">"</span>);
|
||||
System.out.println(<span class="string">"</span><span class="string">n</span><span class="literal">\\</span><span class="string">N next question</span><span class="string">"</span>);
|
||||
s = scan.next();
|
||||
|
||||
<span class="literal">if</span> (s.compareToIgnoreCase(<span class="string">"</span><span class="string">q</span><span class="string">"</span>) == <span class="number">0</span>)
|
||||
{
|
||||
<span class="literal">break</span>;
|
||||
}
|
||||
<span class="literal">else</span> <span class="literal">if</span> (<span class="string">"</span><span class="string">n</span><span class="string">"</span>.compareToIgnoreCase(s) == <span class="number">0</span>)
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">+++++++++++</span><span class="string">"</span> + quiz.nextQuestion() + <span class="string">"</span><span class="string">+++++++++++</span><span class="string">"</span>);
|
||||
|
||||
String answer = <span class="string">""</span>;
|
||||
<span class="literal">do</span>
|
||||
{
|
||||
System.out.println(<span class="string">"</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">"</span>);
|
||||
System.out.println(<span class="string">"</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">"</span>);
|
||||
answer = scan.next();
|
||||
<span class="literal">if</span> (<span class="string">"</span><span class="string">t</span><span class="string">"</span>.compareToIgnoreCase(answer) != <span class="number">0</span> && <span class="string">"</span><span class="string">f</span><span class="string">"</span>.compareToIgnoreCase(answer) != <span class="number">0</span>)
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">f INVALID CHOICE</span><span class="string">"</span>);
|
||||
}
|
||||
|
||||
}
|
||||
<span class="literal">while</span> (<span class="string">"</span><span class="string">t</span><span class="string">"</span>.compareToIgnoreCase(answer) != <span class="number">0</span> && <span class="string">"</span><span class="string">f</span><span class="string">"</span>.compareToIgnoreCase(answer) != <span class="number">0</span>);
|
||||
|
||||
<span class="literal">boolean</span> convertAnswerToBoolean = <span class="string">"</span><span class="string">t</span><span class="string">"</span>.compareToIgnoreCase(answer) == <span class="number">0</span>;
|
||||
|
||||
System.out.println(quiz.isTrue() == convertAnswerToBoolean
|
||||
? <span class="string">"</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">---------correct</span><span class="string">"</span>
|
||||
: <span class="string">"</span><span class="literal">\t</span><span class="literal">\t</span><span class="string">---------incorrect</span><span class="string">"</span>);
|
||||
|
||||
}
|
||||
<span class="literal">else</span>
|
||||
{
|
||||
System.out.println(<span class="string">"</span><span class="string">Invalid choice. Try again</span><span class="string">"</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 < quiz.getTrueFalseQuestions().length; ++i) {
|
||||
System.out.println(quiz.getTrueFalseQuestions()[i].getWhenLastUsed());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
109
Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuestion.html
Normal file
109
Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuestion.html
Normal file
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>TrueFalseQuestion.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}
|
||||
.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/TrueFalseQuestion.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.Date;
|
||||
|
||||
<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> TrueFalseQuestion {
|
||||
|
||||
<span class="literal">private</span> String question;
|
||||
<span class="literal">private</span> <span class="literal">boolean</span> isTrue;
|
||||
<span class="literal">private</span> Date whenLastUsed;
|
||||
|
||||
<span class="literal">public</span> TrueFalseQuestion(){}
|
||||
<span class="literal">public</span> TrueFalseQuestion(String question, <span class="literal">boolean</span> isTrue, Date whenLastUsed) {
|
||||
<span class="literal">this</span>.question = question;
|
||||
<span class="literal">this</span>.isTrue = isTrue;
|
||||
<span class="literal">this</span>.whenLastUsed = whenLastUsed;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenLastUsed</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenLastUsed</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> Date getWhenLastUsed()
|
||||
{
|
||||
<span class="literal">return</span> whenLastUsed;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenLastUsed</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">whenLastUsed</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">whenLastUsed</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> setWhenLastUsed(Date whenLastUsed)
|
||||
{
|
||||
<span class="literal">this</span>.whenLastUsed = whenLastUsed;
|
||||
}
|
||||
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">isTrue</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">isTrue</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> isIsTrue()
|
||||
{
|
||||
<span class="literal">return</span> isTrue;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">isTrue</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">isTrue</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">isTrue</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> setIsTrue(<span class="literal">boolean</span> isTrue)
|
||||
{
|
||||
<span class="literal">this</span>.isTrue = isTrue;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">question</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">question</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> String getQuestion()
|
||||
{
|
||||
<span class="literal">return</span> question;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span><span class="comment">Sets</span> <span class="comment">the</span> <span class="comment">question</span> <span class="comment">to</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">question</span><span class="comment">.</span>
|
||||
<span class="comment"> * </span>
|
||||
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">question</span> <span class="comment">the</span> <span class="comment">new</span> <span class="comment">question</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> setQuestion(String question)
|
||||
{
|
||||
<span class="literal">this</span>.question = question;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
125
Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuiz.html
Normal file
125
Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuiz.html
Normal file
@ -0,0 +1,125 @@
|
||||
<!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>
|
@ -2,7 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.calebfontenot</groupId>
|
||||
<artifactId>lab5_CalebFontenot</artifactId>
|
||||
<artifactId>lab2_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class QuadraticEquation {
|
||||
|
||||
private double a;
|
||||
private double b;
|
||||
private double c;
|
||||
|
||||
public QuadraticEquation(double a, double b, double c)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public double getDiscriminant()
|
||||
{
|
||||
return b * b - 4 * a * c;
|
||||
}
|
||||
|
||||
public double getRoot1()
|
||||
{
|
||||
if (getDiscriminant() < 0) {
|
||||
return -88888888;
|
||||
}
|
||||
return (b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
|
||||
}
|
||||
|
||||
|
||||
public double getRoot2()
|
||||
{
|
||||
if (getDiscriminant() < 0) {
|
||||
return -88888888;
|
||||
}
|
||||
return (-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a);
|
||||
|
||||
//return getDiscriminant() < 0 ? 0
|
||||
// : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "QuadraticEquation{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of b
|
||||
*
|
||||
* @return the value of b
|
||||
*/
|
||||
public double getB()
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of c
|
||||
*
|
||||
* @return the value of c
|
||||
*/
|
||||
public double getC()
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a
|
||||
*
|
||||
* @return the value of a
|
||||
*/
|
||||
public double getA()
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
QuadraticEquation eq1 = new QuadraticEquation(1, -4, 4);
|
||||
System.out.println(eq1);
|
||||
System.out.println(eq1.getRoot1());
|
||||
System.out.println(eq1.getRoot2());
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
}
|
@ -11,43 +11,89 @@ import java.util.Date;
|
||||
* @author caleb
|
||||
*/
|
||||
public class TrueFalseQuiz {
|
||||
|
||||
int currentQuestion;
|
||||
TrueFalseQuestion[] trueFalseQuestions;
|
||||
|
||||
public TrueFalseQuiz() {
|
||||
|
||||
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());
|
||||
|
||||
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) {
|
||||
|
||||
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) {
|
||||
for (int i = 0, j = 0; i < questions.length; ++i, ++j) {
|
||||
trueFalseQuestions[i] = new TrueFalseQuestion(
|
||||
questions[i],
|
||||
trueFalse[j],
|
||||
new Date());
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
BIN
Semester 2/ZIPs/lab2_CalebFontenot.zip
Normal file
BIN
Semester 2/ZIPs/lab2_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user