diff --git a/Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html b/Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html
new file mode 100644
index 0000000..973f9e3
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html
@@ -0,0 +1,123 @@
+
+
+
+QuadraticEquation.java
+
+
+
+
+/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java |
+
+
+nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
+nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
+
+package com.calebfontenot.lab5_calebfontenot;
+
+
+
+@author
+
+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);
+
+
+
+ }
+
+ @Override
+ public String toString()
+ {
+ return "QuadraticEquation{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
+ }
+
+
+
+
+@return
+
+ public double getB()
+ {
+ return b;
+ }
+
+
+
+
+@return
+
+ public double getC()
+ {
+ return c;
+ }
+
+
+
+
+@return
+
+ 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());
+ }
+}
+
+
+
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html b/Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html
new file mode 100644
index 0000000..c66c5a8
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/TakeQuiz.html
@@ -0,0 +1,96 @@
+
+
+
+TakeQuiz.java
+
+
+
+
+/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TakeQuiz.java |
+
+
+
+
+
+package com.calebfontenot.lab5_calebfontenot;
+
+import java.util.Scanner;
+
+
+
+@author
+
+public class TakeQuiz {
+ public static void takeQuiz(TrueFalseQuiz quiz) {
+
+ Scanner scan = new Scanner(System.in);
+ String s = "";
+
+
+ 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());
+ }
+ }
+}
+
+
+
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuestion.html b/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuestion.html
new file mode 100644
index 0000000..2069cf9
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuestion.html
@@ -0,0 +1,109 @@
+
+
+
+TrueFalseQuestion.java
+
+
+
+
+/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuestion.java |
+
+
+
+
+
+package com.calebfontenot.lab5_calebfontenot;
+
+import java.util.Date;
+
+
+
+@author
+
+public class TrueFalseQuestion {
+
+ private String question;
+ private boolean isTrue;
+ private Date whenLastUsed;
+
+ public TrueFalseQuestion(){}
+ public TrueFalseQuestion(String question, boolean isTrue, Date whenLastUsed) {
+ this.question = question;
+ this.isTrue = isTrue;
+ this.whenLastUsed = whenLastUsed;
+ }
+
+
+
+
+@return
+
+ public Date getWhenLastUsed()
+ {
+ return whenLastUsed;
+ }
+
+
+
+
+@param
+
+ public void setWhenLastUsed(Date whenLastUsed)
+ {
+ this.whenLastUsed = whenLastUsed;
+ }
+
+
+
+
+
+@return
+
+ public boolean isIsTrue()
+ {
+ return isTrue;
+ }
+
+
+
+
+@param
+
+ public void setIsTrue(boolean isTrue)
+ {
+ this.isTrue = isTrue;
+ }
+
+
+
+
+@return
+
+ public String getQuestion()
+ {
+ return question;
+ }
+
+
+
+@param
+
+ public void setQuestion(String question)
+ {
+ this.question = question;
+ }
+
+}
+
+
+
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuiz.html b/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuiz.html
new file mode 100644
index 0000000..e51f1fa
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/TrueFalseQuiz.html
@@ -0,0 +1,125 @@
+
+
+
+TrueFalseQuiz.java
+
+
+
+
+/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java |
+
+
+nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
+nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
+
+package com.calebfontenot.lab5_calebfontenot;
+
+import java.util.Date;
+
+
+
+@author
+
+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)
+ {
+
+
+ trueFalseQuestions = new TrueFalseQuestion[questions.length];
+
+
+ for (int i = 0, j = 0; i < questions.length; ++i, ++j) {
+ trueFalseQuestions[i] = new TrueFalseQuestion(
+ questions[i],
+ trueFalse[j],
+ new Date());
+
+ this.currentQuestion = 0;
+ }
+ }
+
+
+
+
+@return
+
+ 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();
+ }
+
+
+@return
+
+ 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;
+ }
+
+}
+
+
+
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/pom.xml b/Semester 2/Assignments/lab2_CalebFontenot/pom.xml
index 34fa50a..f7d0564 100644
--- a/Semester 2/Assignments/lab2_CalebFontenot/pom.xml
+++ b/Semester 2/Assignments/lab2_CalebFontenot/pom.xml
@@ -2,7 +2,7 @@
4.0.0
com.calebfontenot
- lab5_CalebFontenot
+ lab2_CalebFontenot
1.0-SNAPSHOT
jar
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java
new file mode 100644
index 0000000..973ae4f
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java
@@ -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());
+ }
+}
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TakeQuiz.java b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TakeQuiz.java
new file mode 100644
index 0000000..78ce8b5
--- /dev/null
+++ b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TakeQuiz.java
@@ -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());
+ }
+ }
+}
diff --git a/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java
index 89acfea..1e11ac3 100644
--- a/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java
+++ b/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/TrueFalseQuiz.java
@@ -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;
+ }
+
}
diff --git a/Semester 2/ZIPs/lab2_CalebFontenot.zip b/Semester 2/ZIPs/lab2_CalebFontenot.zip
new file mode 100644
index 0000000..8d9f689
Binary files /dev/null and b/Semester 2/ZIPs/lab2_CalebFontenot.zip differ