Finished
This commit is contained in:
@@ -19,13 +19,19 @@ public class DriverExam {
|
|||||||
/** Corresponds to each question, each true if correct answer **/
|
/** Corresponds to each question, each true if correct answer **/
|
||||||
private boolean[] missedQuestions;
|
private boolean[] missedQuestions;
|
||||||
|
|
||||||
// Constructors
|
// Constructor
|
||||||
|
/**
|
||||||
|
* Constructs DE object using an array of given user answers
|
||||||
|
* @param givenAnswers Array of the users given answers
|
||||||
|
*/
|
||||||
public DriverExam(char[] givenAnswers) {
|
public DriverExam(char[] givenAnswers) {
|
||||||
|
// Initialzie givenAnswers array with passed array
|
||||||
this.givenAnswers = givenAnswers;
|
this.givenAnswers = givenAnswers;
|
||||||
// Initialize missedQuestions to length 20. By default, they will all be False
|
// Initialize missedQuestions to length 20. By default, they will all be False
|
||||||
missedQuestions = new boolean[20];
|
missedQuestions = new boolean[20];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares givenAnswers to correctAnswers, counting amount correct
|
* Compares givenAnswers to correctAnswers, counting amount correct
|
||||||
@@ -76,6 +82,7 @@ public class DriverExam {
|
|||||||
*/
|
*/
|
||||||
public ArrayList<Integer> questionsMissed() {
|
public ArrayList<Integer> questionsMissed() {
|
||||||
ArrayList<Integer> missedNums = new ArrayList<>();
|
ArrayList<Integer> missedNums = new ArrayList<>();
|
||||||
|
// Loop and add the index+1 of missed questions
|
||||||
for(int i = 0; i < missedQuestions.length; i++) {
|
for(int i = 0; i < missedQuestions.length; i++) {
|
||||||
if(missedQuestions[i]) {
|
if(missedQuestions[i]) {
|
||||||
missedNums.add(i + 1);
|
missedNums.add(i + 1);
|
||||||
|
|||||||
@@ -3,39 +3,41 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
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'};
|
// To hold the users inputted answers
|
||||||
char[] answers = new char[20];
|
char[] answers = new char[20];
|
||||||
|
|
||||||
|
// Compare against this string for input validation
|
||||||
/// ////////
|
|
||||||
int i = 0;
|
|
||||||
String checkString = "ABCD";
|
String checkString = "ABCD";
|
||||||
|
int i = 0; // Loop variable
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
// Loop until all 20 answers are given
|
||||||
do {
|
do {
|
||||||
System.out.print("Question " + (i+1) + " Student Answer: ");
|
System.out.print("Question " + (i+1) + " Student Answer: ");
|
||||||
String userIn = scanner.nextLine().toUpperCase();
|
String userIn = scanner.nextLine().toUpperCase(); // toUpperCase allows us to accept lowercase letters
|
||||||
|
|
||||||
|
// Reject the answer if it isnt just a letter
|
||||||
if(userIn.length() != 1){
|
if(userIn.length() != 1){
|
||||||
System.out.println("Please input only a single letter A,B,C,or D");
|
System.out.println("Please input only a single letter A,B,C,or D");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Reject the answer if it isnt A, B, C, or D
|
||||||
if(!checkString.contains(userIn)) {
|
if(!checkString.contains(userIn)) {
|
||||||
System.out.println("Please input only a single letter A,B,C,or D");
|
System.out.println("Please input only a single letter A,B,C,or D");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Add to array and iterate if the answer is good
|
||||||
answers[i] = userIn.charAt(0);
|
answers[i] = userIn.charAt(0);
|
||||||
i++;
|
i++;
|
||||||
} while (i < 20);
|
} while (i < 20);
|
||||||
|
|
||||||
/// ///////
|
// Test methods for class
|
||||||
|
|
||||||
DriverExam test = new DriverExam(answers);
|
DriverExam test = new DriverExam(answers);
|
||||||
|
System.out.println("Passed: " + test.passed());
|
||||||
System.out.println(test.passed());
|
System.out.println("Total Correct: " + test.totalCorrect());
|
||||||
System.out.println(test.totalCorrect());
|
System.out.println("Total Incorrect: " + test.totalIncorrect());
|
||||||
System.out.println(test.totalIncorrect());
|
System.out.print("Questions Numbers Missed: ");
|
||||||
ArrayList<Integer> missed = test.questionsMissed();
|
ArrayList<Integer> missed = test.questionsMissed();
|
||||||
|
|
||||||
for(var x : missed) {
|
for(var x : missed) {
|
||||||
System.out.print(x + " ");
|
System.out.print(x + " ");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user