Added some Javadocs
This commit is contained in:
@@ -5,26 +5,39 @@ import java.util.ArrayList;
|
||||
* and handles logic for calculating if the user passed, and displays incorrect answers
|
||||
*/
|
||||
public class DriverExam {
|
||||
/** Array of correct exam answers. IStatic because it does not change or depends on which
|
||||
* user is taking the exam
|
||||
**/
|
||||
/** Array of correct exam answers. Is Static because it does not change or depends on which user is taking
|
||||
* the exam **/
|
||||
private final static char[] correctAnswers =
|
||||
{'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};
|
||||
|
||||
/** Array of user's answers **/
|
||||
/** Array of the user's answers **/
|
||||
private final char[] givenAnswers;
|
||||
|
||||
/** Count of correct user answers **/
|
||||
private int totalCorrect;
|
||||
|
||||
/** Corresponds to each question, each true if correct answer **/
|
||||
private boolean[] missedQuestions;
|
||||
|
||||
// Constructors
|
||||
public DriverExam(char[] givenAnswers) {
|
||||
this.givenAnswers = givenAnswers;
|
||||
// Initialize missedQuestions to length 20. By default, they will all be False
|
||||
missedQuestions = new boolean[20];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares givenAnswers to correctAnswers, counting amount correct
|
||||
* Also updates missedQuestions with incorrect answers
|
||||
* 15 out of 20 is required to pass
|
||||
* @return If user passed exam
|
||||
*/
|
||||
public boolean passed() {
|
||||
// Count correct answers
|
||||
int correct = 0;
|
||||
// Loop through and compare givenAnswers to Correct Answer
|
||||
// Updating correct count, or missedQuestions when needed
|
||||
for(int i = 0; i < givenAnswers.length; i++) {
|
||||
if(givenAnswers[i] == correctAnswers[i]) {
|
||||
correct++;
|
||||
@@ -33,22 +46,34 @@ public class DriverExam {
|
||||
missedQuestions[i] = true;
|
||||
}
|
||||
}
|
||||
// Update member
|
||||
totalCorrect = correct;
|
||||
return correct >= 15;
|
||||
}
|
||||
|
||||
public DriverExam(char[] givenAnswers) {
|
||||
this.givenAnswers = givenAnswers;
|
||||
missedQuestions = new boolean[20];
|
||||
}
|
||||
|
||||
// Getter methods
|
||||
|
||||
/**
|
||||
* Returns count of correct answers
|
||||
* @return Count of correct answers
|
||||
*/
|
||||
public int totalCorrect() {
|
||||
return totalCorrect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns count of incorrect answers, by subtracting correct from 20
|
||||
* @return Count of incorrect answers
|
||||
*/
|
||||
public int totalIncorrect() {
|
||||
return 20 - totalCorrect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the question number of the missed questions to an arraylist so we can have a list of the incorrect
|
||||
* @return Arraylist with the numbers of the incorrectly answered questions
|
||||
*/
|
||||
public ArrayList<Integer> questionsMissed() {
|
||||
ArrayList<Integer> missedNums = new ArrayList<>();
|
||||
for(int i = 0; i < missedQuestions.length; i++) {
|
||||
|
||||
@@ -5,15 +5,17 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
//char[] answers = {'A','B','F','F','F','F','F','A','C','D','B','C','D','A','D','C','C','B','D','A'};
|
||||
char[] answers = new char[20];
|
||||
|
||||
|
||||
/// ////////
|
||||
int i = 0;
|
||||
String checkString = "ABCD";
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
do {
|
||||
System.out.print("Question " + (i+1) + " Student Answer: ");
|
||||
String userIn = scanner.nextLine();
|
||||
String userIn = scanner.nextLine().toUpperCase();
|
||||
|
||||
if(userIn.length() > 1){
|
||||
if(userIn.length() != 1){
|
||||
System.out.println("Please input only a single letter A,B,C,or D");
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user