Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Part02
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
Assessment
Part02
Commits
e9c3cf05
Commit
e9c3cf05
authored
Nov 26, 2018
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
11:12 26/11/18
parent
01df26df
Pipeline
#338
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
4 deletions
+82
-4
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+78
-3
AssessmentPartTwoTest.java
src/AssessmentPartTwoTest.java
+4
-1
No files found.
src/AssessmentPartTwo.java
View file @
e9c3cf05
...
@@ -13,9 +13,29 @@ public class AssessmentPartTwo {
...
@@ -13,9 +13,29 @@ public class AssessmentPartTwo {
// You will need to come up with a way of connecting each letter to its score and
// 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.
// a way of identifying each letter in the word.
return
0
;
int
intWordScore
=
0
;
int
intScoreArr
[]
=
{
1
,
3
,
3
,
2
,
1
,
4
,
2
,
4
,
1
,
8
,
5
,
1
,
3
,
1
,
1
,
3
,
10
,
1
,
1
,
1
,
1
,
4
,
4
,
8
,
4
,
10
};
//Scrabble score a b c d e f g h i j k l m n o p q r s t u v w x y z
aWord
=
aWord
.
toLowerCase
();
//converts string to lowercase
char
chaWordArr
[]
=
aWord
.
toCharArray
();
//places string into array as ASCII chars
for
(
int
i
=
0
;
i
<
chaWordArr
.
length
;
i
++)
{
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
if
((
chaWordArr
[
i
]
<
97
)
||
(
chaWordArr
[
i
]
>
122
))
{
continue
;
}
intWordScore
=
intWordScore
+
intScoreArr
[(
chaWordArr
[
i
]-
97
)];
//Char's ASCII code - 97 = Char's position in intScoreArr
}
return
intWordScore
;
}
}
public
Boolean
passwordValidator
(
String
password
)
public
Boolean
passwordValidator
(
String
password
)
{
{
...
@@ -24,11 +44,66 @@ public class AssessmentPartTwo {
...
@@ -24,11 +44,66 @@ public class AssessmentPartTwo {
// is a valid password
// is a valid password
// A password is valid if it is
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$%
// - 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
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
// - does not contain the phrases 'password' or 'passwd'
return
false
;
boolean
booPasswordLength
=
false
;
boolean
booPasswordChars
=
false
;
boolean
booPasswordUpper
=
false
;
boolean
booPasswordLower
=
false
;
boolean
booPasswordNum
=
false
;
boolean
booPasswordUpperLowerNum
=
false
;
boolean
booPasswordIsPassword
=
false
;
char
passwordArr
[]
=
password
.
toCharArray
();
//true == correct, false == incorrect
//Password length between 8 and 16 characters
booPasswordLength
=
((
password
.
length
()
>=
8
)
&&
(
password
.
length
()
<=
16
))
?
true
:
false
;
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for
(
int
i
=
0
;
i
<
passwordArr
.
length
;
i
++)
{
//, ,
if
((
passwordArr
[
i
]
>=
48
)
&&
(
passwordArr
[
i
]
<=
57
))
{
booPasswordChars
=
true
;
booPasswordNum
=
true
;
}
else
if
((
passwordArr
[
i
]
>=
65
)
&&
(
passwordArr
[
i
]
<=
90
))
//65 - 90 = A - B
{
booPasswordChars
=
true
;
booPasswordUpper
=
true
;
}
else
if
((
passwordArr
[
i
]
>=
97
)
&&
(
passwordArr
[
i
]
<=
122
))
// 97 - 122 = a - b
{
booPasswordChars
=
true
;
booPasswordLower
=
true
;
}
else
if
(
passwordArr
[
i
]
==
33
||
passwordArr
[
i
]
==
63
||
passwordArr
[
i
]
==
36
||
passwordArr
[
i
]
==
37
)
//33 = !, 63 = ?, 36 = $, 37 = %
{
booPasswordChars
=
true
;
}
else
{
booPasswordChars
=
false
;
return
false
;
}
//FUCK SAKE. LOOK UP REGEXES.
}
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
for
(
int
i
=
0
;
i
<
passwordArr
.
length
;
i
++)
return
booPasswordChars
;
}
}
}
}
src/AssessmentPartTwoTest.java
View file @
e9c3cf05
...
@@ -23,7 +23,10 @@ class AssessmentPartTwoTest {
...
@@ -23,7 +23,10 @@ class AssessmentPartTwoTest {
"speaker,13"
,
"speaker,13"
,
"exactly,19"
,
"exactly,19"
,
"xylophone,24"
,
"xylophone,24"
,
"application,17"
"application,17"
,
"123567, 0"
,
//NW not letters test
"rabbit!,10"
,
//NW mixed letters and not letters test
"RaBbIt, 10"
//NW mixed case letters
})
})
void
testScrabbleScore
(
String
theWord
,
int
expectedScore
)
{
void
testScrabbleScore
(
String
theWord
,
int
expectedScore
)
{
assertEquals
(
expectedScore
,
test
.
scrabbleScore
(
theWord
));
assertEquals
(
expectedScore
,
test
.
scrabbleScore
(
theWord
));
...
...
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