Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment02-18
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
william.leather
Assessment02-18
Commits
5ae8b51d
Commit
5ae8b51d
authored
Dec 31, 2018
by
william.leather
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace AssessmentPartTwo.java
parent
01df26df
Pipeline
#560
failed with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
34 deletions
+129
-34
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+129
-34
No files found.
src/AssessmentPartTwo.java
View file @
5ae8b51d
public
class
AssessmentPartTwo
{
public
int
scrabbleScore
(
String
aWord
)
{
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// In scrabble each letter is worth a number of points and each word is worth the
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// You will need to come up with a way of connecting each letter to its score and
// a way of identifying each letter in the word.
return
0
;
}
public
Boolean
passwordValidator
(
String
password
)
{
// 04 - Password Validator
// Complete this method to validate that the String password
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
return
false
;
}
}
import
java.util.regex.Pattern
;
public
class
AssessmentPartTwo
{
public
int
scrabbleScore
(
String
aWord
)
{
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// In scrabble each letter is worth a number of points and each word is worth the
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// You will need to come up with a way of connecting each letter to its score and
// a way of identifying each letter in the word.
int
finalresult
=
0
;
int
i
=
0
;
while
(
i
<
aWord
.
length
()-
1
);
//initiates the loop until the condition is false, to check every single character of the word
{
char
letter
=
aWord
.
charAt
(
i
);
//letter receives the character from the word, in position i, and treats it similar to an array.
if
((
letter
==
'a'
)
||
(
letter
==
'e'
)
||
(
letter
==
'i'
)
||
(
letter
==
'o'
)
||
(
letter
==
'n'
)
||
(
letter
==
'r'
)
||
(
letter
==
't'
)
||
(
letter
==
'l'
)
||
(
letter
==
's'
)
||
(
letter
==
'u'
))
{
finalresult
=
finalresult
+
1
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 1 point
}
else
if
((
letter
==
'd'
)||(
letter
==
'g'
))
{
finalresult
=
finalresult
+
2
;
//this goes through these 2 letters mentioned and if the word has ANY of them in it,
//it will give 2 points
}
else
if
((
letter
==
'b'
)||(
letter
==
'c'
)||(
letter
==
'm'
)||(
letter
==
'p'
))
{
finalresult
=
finalresult
+
3
;
//this will search through the letters mentioned and if the word has ANY of them in it,
//it will give 3 points
}
else
if
((
letter
==
'f'
)||(
letter
==
'h'
)||(
letter
==
'v'
)||(
letter
==
'w'
)||(
letter
==
'y'
))
{
finalresult
=
finalresult
+
4
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 4 points
}
else
if
(
letter
==
'k'
)
{
finalresult
=
finalresult
+
5
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 5 points
}
else
if
((
letter
==
'j'
)||(
letter
==
'x'
))
{
finalresult
=
finalresult
+
8
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 8 points
}
else
if
((
letter
==
'q'
)
||
(
letter
==
'z'
))
{
finalresult
=
finalresult
+
10
;
//this will search through letters mentioned and if the word has ANY of them in it,
//it will give 10 points
}
i
++;
//goes through to the next letter in the word until it reaches the last letter
}
return
finalresult
;
//returns the total points for the word
}
public
Boolean
passwordValidator
(
String
password
)
{
// 04 - Password Validator
// Complete this method to validate that the String password
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !�$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
Pattern
specialCharPatten
=
Pattern
.
compile
(
"[^a-z0-9 ]"
,
Pattern
.
CASE_INSENSITIVE
);
Pattern
UpperCasePatten
=
Pattern
.
compile
(
"[A-Z ]"
);
Pattern
lowerCasePatten
=
Pattern
.
compile
(
"[a-z ]"
);
Pattern
digitCasePatten
=
Pattern
.
compile
(
"[0-9 ]"
);
//uses the java.util.regex.Pattern from java where it compares every letter of the password
//uses the java.util.regex.Pattern from java to search for upper case
//uses the java.util.regex.Pattern from java to search for lower case
//uses the java.util.regex.Pattern from java to search for numbers and special characters
boolean
flag
=
true
;
//turn the final result into a boolean variable to use in every condition
if
((
password
.
length
()
<
8
)
&&
(
password
.
length
()
>
16
))
{
flag
=
false
;
//check if password is between 8-16 characters inclusive if not returns false
}
if
(!
specialCharPatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search for any special characters and also special words in it for example password
//if not returns false
}
if
(!
UpperCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains upper case if not returns false
}
if
(!
lowerCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains lower case if not returns false
}
if
(!
digitCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains any numbers, if not returns false
}
return
flag
;
//returns the final result if password is valid or not
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment