Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment Part 2
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
jack.templeman
Assessment Part 2
Commits
cb987464
Commit
cb987464
authored
Nov 27, 2018
by
jackt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete Part 2
parent
01df26df
Pipeline
#342
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
3 deletions
+124
-3
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+124
-3
No files found.
src/AssessmentPartTwo.java
View file @
cb987464
...
@@ -12,8 +12,62 @@ public class AssessmentPartTwo {
...
@@ -12,8 +12,62 @@ public class AssessmentPartTwo {
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// 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
// 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.
int
total
=
0
;
for
(
int
length
=
0
;
length
<
aWord
.
length
();
length
++)
// for loop to count up through the word length
{
char
aChar
=
aWord
.
charAt
(
length
);
// selects the letter at the current char placement
Character
.
toString
(
aChar
);
// converts the char to a string value
switch
(
String
.
valueOf
(
aChar
))
{
// switch statement to allow for loop to select the correct string and add the corresponding value
case
"a"
:
case
"A"
:
case
"e"
:
case
"E"
:
case
"i"
:
case
"I"
:
case
"o"
:
case
"O"
:
case
"n"
:
case
"N"
:
case
"r"
:
case
"R"
:
case
"t"
:
case
"T"
:
case
"l"
:
case
"L"
:
case
"s"
:
case
"S"
:
case
"u"
:
case
"U"
:
total
=
total
+
1
;
break
;
case
"d"
:
case
"D"
:
case
"g"
:
case
"G"
:
total
=
total
+
2
;
break
;
case
"b"
:
case
"B"
:
case
"c"
:
case
"C"
:
case
"m"
:
case
"M"
:
case
"p"
:
case
"P"
:
total
=
total
+
3
;
break
;
case
"f"
:
case
"F"
:
case
"h"
:
case
"H"
:
case
"v"
:
case
"V"
:
case
"w"
:
case
"W"
:
case
"y"
:
case
"Y"
:
total
=
total
+
4
;
break
;
case
"k"
:
case
"K"
:
total
=
total
+
5
;
break
;
case
"j"
:
case
"J"
:
case
"x"
:
case
"X"
:
total
=
total
+
8
;
break
;
case
"q"
:
case
"Q"
:
case
"z"
:
case
"Z"
:
total
=
total
+
10
;
break
;
default
:
throw
new
IllegalArgumentException
(
"Invalid Scrabble Letter"
+
aWord
);
// this is to be used when an invalid character in input into the console
}
}
return
total
;
// returns total of the scrabble score
return
0
;
}
}
...
@@ -28,7 +82,74 @@ public class AssessmentPartTwo {
...
@@ -28,7 +82,74 @@ public class AssessmentPartTwo {
// - 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
;
int
lengthP
=
password
.
length
();
boolean
passwd
=
true
;
boolean
upperCase
=
false
;
boolean
lowerCase
=
false
;
// booleans to set up multiple tests to ensure all criterias are met
boolean
character
=
true
;
boolean
number
=
false
;
boolean
lengthA
=
false
;
boolean
finalTest
=
false
;
String
test
=
password
;
// used to see the variable when debugging
if
(
lengthP
>=
8
&&
lengthP
<=
16
)
{
// ensures the password is between 8-16 characters (inclusively)
lengthA
=
true
;
}
for
(
int
i
=
0
;
i
<
password
.
length
();
i
++)
//for loop to cycle through each character of the given password
{
String
cTwo
=
""
;
// used to see the variable when debugging
char
charTwo
=
password
.
charAt
(
i
);
// selects the letter at the current char placement
Character
special
=
Character
.
toLowerCase
(
charTwo
);
//converts character to lowercase to halve the ascii range
String
poundTest
=
Character
.
toString
(
charTwo
);
//converts character to a string to test for a £ which is not included in ascii
int
speciall
=
(
int
)
special
;
//converts password char to ascii code to ensure it is part of the allowed character range
if
(!(
speciall
>=
97
&&
speciall
<=
122
||
speciall
>=
48
&&
speciall
<=
57
||
speciall
==
33
||
speciall
==
36
||
speciall
==
37
||
poundTest
.
equals
(
"£"
)))
// makes sure characters are only the permitted ones
{
finalTest
=
false
;
return
finalTest
;
}
if
(
Character
.
isUpperCase
(
charTwo
))
{
// checks for an uppercase character
upperCase
=
true
;
}
if
(
Character
.
isLowerCase
(
charTwo
))
// checks for a lowercase character
{
lowerCase
=
true
;
}
if
(
Character
.
isDigit
(
charTwo
))
//checks for a number
{
number
=
true
;
}
if
(
password
.
toLowerCase
().
contains
(
"password"
)
||
password
.
toLowerCase
().
contains
(
"passwd"
))
{
passwd
=
false
;
// takes the password, converts it to lowercase and then checks for the phrases "password"
}
// and "passwd" to ensure all combinations of case are covered
}
if
(
passwd
==
true
&&
upperCase
==
true
&&
lowerCase
==
true
&&
character
==
true
&&
number
==
true
&&
lengthA
==
true
)
{
finalTest
=
true
;
// if all the loop tests are true then the final result will become true as the password passes
}
return
finalTest
;
}
}
}
}
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