Reset author name to chosen name ✨
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab5_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of whenLastUsed
|
||||
*
|
||||
* @return the value of whenLastUsed
|
||||
*/
|
||||
public Date getWhenLastUsed()
|
||||
{
|
||||
return whenLastUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of whenLastUsed
|
||||
*
|
||||
* @param whenLastUsed new value of whenLastUsed
|
||||
*/
|
||||
public void setWhenLastUsed(Date whenLastUsed)
|
||||
{
|
||||
this.whenLastUsed = whenLastUsed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of isTrue
|
||||
*
|
||||
* @return the value of isTrue
|
||||
*/
|
||||
public boolean isIsTrue()
|
||||
{
|
||||
return isTrue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of isTrue
|
||||
*
|
||||
* @param isTrue new value of isTrue
|
||||
*/
|
||||
public void setIsTrue(boolean isTrue)
|
||||
{
|
||||
this.isTrue = isTrue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of question
|
||||
*
|
||||
* @return the value of question
|
||||
*/
|
||||
public String getQuestion()
|
||||
{
|
||||
return question;
|
||||
}
|
||||
|
||||
/**Sets the question to a new question.
|
||||
*
|
||||
* @param question the new question
|
||||
*/
|
||||
public void setQuestion(String question)
|
||||
{
|
||||
this.question = question;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab5_chloefontenot;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user