Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assesment 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
romain.vasseur
Assesment part 2
Commits
84c104aa
Commit
84c104aa
authored
Dec 10, 2018
by
Romain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final update
parent
83770f73
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
27 deletions
+31
-27
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+31
-27
No files found.
src/AssessmentPartTwo.java
View file @
84c104aa
...
...
@@ -13,17 +13,18 @@ public class AssessmentPartTwo {
// 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
total
=
0
;
int
point
=
0
;
boolean
to
=
false
;
int
total
=
0
;
//create a variable to store the number of points in a word
int
point
=
0
;
// create a variable to connect each letter to their number of points
boolean
to
=
false
;
// Create a boolean to take in account problem in aWord (number, special characters...)
aWord
=
aWord
.
toLowerCase
();
// to be sure each letter is in the same format before the loop
for
(
int
j
=
0
;
j
<
aWord
.
length
();
j
++)
for
(
int
j
=
0
;
j
<
aWord
.
length
();
j
++)
// Create a loop that run each letter in aWord
{
switch
(
aWord
.
charAt
(
j
))
switch
(
aWord
.
charAt
(
j
))
//Create a switch for each letter in the alphabet and link each letter to their number of points.
{
case
'a'
:
case
'o'
:
case
'e'
:
case
'i'
:
case
'n'
:
case
'r'
:
case
't'
:
case
'l'
:
case
's'
:
case
'u'
:
point
=
1
;
total
=
total
+
point
;
total
=
total
+
point
;
// total take total + the number of point for the letter
break
;
case
'd'
:
case
'g'
:
point
=
2
;
total
=
total
+
point
;
...
...
@@ -44,18 +45,19 @@ public class AssessmentPartTwo {
total
=
total
+
point
;
break
;
default
:
to
=
true
;
to
=
true
;
// if the letter is not a letter
total
=
0
;
// total = 0 if something is not a letter in aWord
break
;
}
}
if
(
to
==
false
)
if
(
to
==
false
)
// if all going well
{
System
.
out
.
print
(
total
);
}
else
{
System
.
out
.
println
(
"Error"
);
System
.
out
.
println
(
"Error"
);
// if something is wrong
}
return
total
;
}
...
...
@@ -71,17 +73,19 @@ public class AssessmentPartTwo {
// - 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'
boolean
pass
=
false
;
boolean
valid
=
false
;
boolean
lowerCase
=
false
;
boolean
upperCase
=
false
;
boolean
number
=
false
;
boolean
test
=
false
;
boolean
specialChar
=
false
;
boolean
error
=
false
;
// create some boolean to check if each condition is ok or not
boolean
pass
=
false
;
// final boolean to store if the password is good or wrong
boolean
valid
=
false
;
// boolean to store if the password is between 8 and 16 characters long (inclusive)
boolean
lowerCase
=
false
;
// boolean to store if at least one letter is a lower case
boolean
upperCase
=
false
;
// boolean to store if at least one letter is a upper case
boolean
number
=
false
;
// boolean to store if at least one character is a number
boolean
test
=
false
;
// boolean to store the test result
boolean
specialChar
=
false
;
// boolean to check if a special character is use or not
boolean
error
=
false
;
// boolean to store if something is wrong
if
(
password
.
length
()>=
8
&
password
.
length
()<=
16
)
if
(
password
.
length
()>=
8
&
password
.
length
()<=
16
)
// first test for the password length
{
valid
=
true
;
}
...
...
@@ -89,31 +93,31 @@ public class AssessmentPartTwo {
valid
=
false
;
}
for
(
int
i
=
0
;
i
<
password
.
length
();
i
++)
for
(
int
i
=
0
;
i
<
password
.
length
();
i
++)
// loop to run each letter in the password
{
if
(
Character
.
isLowerCase
(
password
.
charAt
(
i
))==
true
)
if
(
Character
.
isLowerCase
(
password
.
charAt
(
i
))==
true
)
// test if the character is a lower case
{
lowerCase
=
true
;
}
else
{
if
(
Character
.
isUpperCase
(
password
.
charAt
(
i
))==
true
)
if
(
Character
.
isUpperCase
(
password
.
charAt
(
i
))==
true
)
// test if the character is a upper case
{
upperCase
=
true
;
}
else
{
if
(
Character
.
isDigit
(
password
.
charAt
(
i
))==
true
)
if
(
Character
.
isDigit
(
password
.
charAt
(
i
))==
true
)
// test if the character is a digit
{
number
=
true
;
}
else
{
switch
(
password
.
charAt
(
i
))
switch
(
password
.
charAt
(
i
))
// switch to take in account the special character
{
case
'!'
:
case
'%'
:
case
'$'
:
case
'£'
:
test
=
true
;
specialChar
=
true
;
error
=
false
;
break
;
default
:
test
=
false
;
error
=
true
;
default
:
test
=
false
;
// if password is build with another character than above
error
=
true
;
break
;
}
...
...
@@ -127,12 +131,12 @@ public class AssessmentPartTwo {
}
if
(
password
.
toLowerCase
().
contains
(
"password"
)|
password
.
toLowerCase
().
contains
(
"passwd"
))
if
(
password
.
toLowerCase
().
contains
(
"password"
)|
password
.
toLowerCase
().
contains
(
"passwd"
))
// test if the password contains password or passwd
{
valid
=
false
;
}
if
(
lowerCase
==
true
&
upperCase
==
true
&
valid
==
true
&
number
==
true
&
error
==
false
)
if
(
lowerCase
==
true
&
upperCase
==
true
&
valid
==
true
&
number
==
true
&
error
==
false
)
// final condition test
{
pass
=
true
;
}
...
...
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