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

Final Refactor of User Object

parent 2bfc8487
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,11 @@ import java.util.ArrayList;
public class User {
/*
Class to represent a User, includes the User's name and a record of which
lessons, quizzes and scores they have completed.
*/
private String username;
private ArrayList<Lesson> userRecord;
......@@ -24,21 +29,25 @@ public class User {
// CUSTOM METHODS
/**
* Checks if the user already has a record and updates quiz score if necessary or adds the current
* lesson data to the user record
* Checks the Users record to see if they have already completed the lesson and/or quiz for that Lesson
* object. If not then their record is updated to show what they have done for that Lesson.
* @param currentLesson
*/
public void addToUserRecord(Lesson currentLesson) {
boolean inUserRecord = false;
int userPlace = 0;
int lessonsPlaceInRecord = 0;
// Check to see if currentLesson is in the user record already
for(int i = 0; i < userRecord.size(); i++) {
if(userRecord.get(i).getLessonTitle().equals(currentLesson.getLessonTitle())){
inUserRecord = true;
userPlace = i;
lessonsPlaceInRecord = i;
}
}
// Update or create the lesson in the user record
if(inUserRecord) {
userRecord.get(userPlace).setQuizScore(currentLesson.getQuizScore());
userRecord.get(lessonsPlaceInRecord).setQuizScore(currentLesson.getQuizScore());
} else {
userRecord.add(currentLesson);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment