Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
Java Coursework
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Barrett
Java Coursework
Commits
426a1d34
Commit
426a1d34
authored
3 years ago
by
Simon Barrett
Browse files
Options
Downloads
Patches
Plain Diff
Final Refactor of User Object
parent
2bfc8487
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/User.java
+14
-5
14 additions, 5 deletions
src/User.java
with
14 additions
and
5 deletions
src/User.java
+
14
−
5
View file @
426a1d34
...
...
@@ -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
u
ser
alread
y ha
s
a
re
cord and updates quiz score if necessary or adds the current
*
lesson
dat
a
to
the user record
* Checks the
U
ser
s record to see if the
y ha
ve
a
l
re
ady completed the lesson and/or quiz for that Lesson
*
object. If not then their record is up
dat
ed
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
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment