Skip to content
Snippets Groups Projects
Commit 439abd90 authored by Simon Barrett's avatar Simon Barrett
Browse files

Refactored Print user dat into user completion data to make more sense

parent 984e4076
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -30,8 +30,7 @@ public class Lesson {
}
/* GETTER METHODS
Standard getter methods
Getter methods for 4 fields aren't needed at the moment so not added to minimise code
4 Standard getter methods
*/
public String getLessonTitle() {
return lessonTitle;
......@@ -41,6 +40,20 @@ public class Lesson {
return quizScore;
}
public boolean isLessonCompleted() {
return lessonCompleted;
}
public boolean isQuizCompleted() {
return quizCompleted;
}
// This is only called in one place so rather than a getter and then call .length it
// has been combined here for readability.
public int getQuestionArrayLength() {
return questionArray.length;
}
// END GETTER METHODS
/* SETTER METHODS
......@@ -65,22 +78,6 @@ public class Lesson {
// CUSTOM METHODS
/**
* Returns a string based on if the user has completed the lesson or quiz
* Though the method currently isn't called when lessonCompleted == false, this functionality has been added
* in case it is used differently in the future
* @return
*/
public String printOutUserCompletionDataForLesson() {
if(lessonCompleted == false) {
return " has not completed the lesson or quiz for " + lessonTitle;
} else if(quizCompleted == false) {
return " has completed the lesson for " + lessonTitle + " but not the quiz";
} else {
return " has completed the lesson and quiz for " + lessonTitle + ", with a score of " + quizScore + "/" + questionArray.length;
}
}
/**
* Prints out the lesson title followed by the lesson text with empty lines in between for styling
* <p>
......
......@@ -129,8 +129,9 @@ public class ScannerExtension {
}
} else {
ArrayList<Lesson> userRecord= users.getUsers().get(userExists).getUserRecord();
UserCompletionData userCompletionData = users;
for(int i = 0; i < userRecord.size(); i++) {
System.out.println(nextString + ":" + userRecord.get(i).printOutUserCompletionDataForLesson());
System.out.println(nextString + ":" + users.printOutUserCompletionDataForLesson(userRecord.get(i)));
}
correctEntry = true;
}
......
......@@ -37,6 +37,22 @@ public class UserCompletionData {
}
return -1;
}
/**
* Returns a string based on if the user has completed the lesson or quiz
* Though the method currently isn't called when lessonCompleted == false, this functionality has been added
* in case it is used differently in the future
* @return
*/
public String printOutUserCompletionDataForLesson(Lesson lesson) {
String lessonTitle = lesson.getLessonTitle();
if(lesson.isLessonCompleted() == false) {
return " has not completed the lesson or quiz for " + lessonTitle;
} else if(lesson.isQuizCompleted() == false) {
return " has completed the lesson for " + lessonTitle + " but not the quiz";
} else {
return " has completed the lesson and quiz for " + lessonTitle + ", with a score of " + lesson.getQuizScore() + "/" + lesson.getQuestionArrayLength();
}
}
/**
* Prints out every users completion data
......@@ -45,7 +61,7 @@ public class UserCompletionData {
for(int i = 0; i < users.size(); i++) {
User currentUser = users.get(i);
for (int j = 0; j < currentUser.getUserRecord().size(); j++) {
System.out.println(currentUser.getUsername() + currentUser.getUserRecord().get(j).printOutUserCompletionDataForLesson());
System.out.println(currentUser.getUsername() + printOutUserCompletionDataForLesson(currentUser.getUserRecord().get(j)));
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment