Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming 01 Task 3-4
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
christopher.spray
Programming 01 Task 3-4
Commits
f6841e1b
Commit
f6841e1b
authored
Jan 07, 2019
by
spray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OG upload
parent
01df26df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
2 deletions
+82
-2
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+82
-2
No files found.
src/AssessmentPartTwo.java
View file @
f6841e1b
import
java.util.HashMap
;
public
class
AssessmentPartTwo
{
public
class
AssessmentPartTwo
{
...
@@ -13,7 +14,44 @@ public class AssessmentPartTwo {
...
@@ -13,7 +14,44 @@ 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
totalpoints
=
0
;
HashMap
<
String
,
Integer
>
values
=
new
HashMap
<>();
//created a Hashmap to store each letter of the alphabet and their corresponding value
values
.
put
(
"a"
,
1
);
//add a and value to hashmap
values
.
put
(
"b"
,
3
);
//rinse and repeat
values
.
put
(
"c"
,
3
);
values
.
put
(
"d"
,
2
);
values
.
put
(
"e"
,
1
);
values
.
put
(
"f"
,
4
);
values
.
put
(
"g"
,
2
);
values
.
put
(
"h"
,
4
);
values
.
put
(
"i"
,
1
);
values
.
put
(
"j"
,
8
);
values
.
put
(
"k"
,
5
);
values
.
put
(
"l"
,
1
);
values
.
put
(
"m"
,
3
);
values
.
put
(
"n"
,
1
);
values
.
put
(
"o"
,
1
);
values
.
put
(
"p"
,
3
);
values
.
put
(
"q"
,
10
);
values
.
put
(
"r"
,
1
);
values
.
put
(
"s"
,
1
);
values
.
put
(
"t"
,
1
);
values
.
put
(
"u"
,
1
);
values
.
put
(
"v"
,
4
);
values
.
put
(
"w"
,
4
);
values
.
put
(
"x"
,
8
);
values
.
put
(
"y"
,
4
);
values
.
put
(
"z"
,
10
);
String
[]
splitWord
=
aWord
.
split
(
""
);
//split the word into chars
for
(
int
i
=
0
;
i
<
splitWord
.
length
;
i
++)
{
//while i < length of word
totalpoints
+=
values
.
get
(
splitWord
[
i
]);
//total value of the word = itself + next letter value
}
return
totalpoints
;
}
}
...
@@ -28,7 +66,49 @@ public class AssessmentPartTwo {
...
@@ -28,7 +66,49 @@ 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
letter
=
0
;
//initialize bunch of variables
int
digit
=
0
;
int
upper
=
0
;
int
lower
=
0
;
int
specChar
=
1
;
char
[]
pWord
=
password
.
toCharArray
();
//put the password string into a char array
if
(
pWord
.
length
>=
8
&&
pWord
.
length
<=
16
)
{
//if the char array is between 8 and 16
if
(
password
.
contains
(
"password"
))
{
//if the password is 'password'
return
false
;
//dont validate
}
if
(
password
.
contains
(
"passwd"
))
{
//if the password is 'passwd'
return
false
;
//dont validate
}
for
(
int
i
=
0
;
i
<=
pWord
.
length
-
1
;
i
++)
{
//when i is smaller than length of the Char array
//these check if there all of the requirements are met
if
(
Character
.
isAlphabetic
(
pWord
[
i
]))
{
//if the character is a letter in the alphabet
letter
+=
1
;
//add 1 to letter variable
}
if
(
Character
.
isDigit
(
pWord
[
i
]))
{
//if the character is a number
digit
+=
1
;
//add 1 to digit variable
}
if
(
Character
.
isUpperCase
(
pWord
[
i
]))
{
//if the character is Uppercase
upper
+=
1
;
//add 1 to upper variable
}
if
(
Character
.
isLowerCase
(
pWord
[
i
]))
{
//of the character is Lowercase
lower
+=
1
;
//add 1 to lower variable
}
if
(
pWord
[
i
]
==
'!'
||
pWord
[
i
]
==
'£'
||
pWord
[
i
]
==
'$'
||
pWord
[
i
]
==
'%'
)
{
//if the character is one of the special characters
specChar
+=
1
;
//add 1 to specChar variable
}
}
}
if
(
letter
>
0
&&
digit
>
0
&&
upper
>
0
&&
lower
>
0
&&
specChar
>
0
)
{
//if all of the requirements have been met at least once
return
true
;
//validate the password
}
return
false
;
//if non of the conditions are met, return false
}
}
}
}
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