Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment2
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
benn.robinson
Assessment2
Commits
f2838112
Commit
f2838112
authored
Jan 07, 2019
by
benn.robinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AssessmentPartTwo.java
parent
b27a60bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
34 deletions
+120
-34
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+120
-34
No files found.
src/AssessmentPartTwo.java
View file @
f2838112
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
;
}
}
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
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 to a string value
Character
.
toLowerCase
(
aChar
);
// converts to lowercase so that it matches
switch
(
String
.
valueOf
(
aChar
))
{
// Allows the selection of the correct string, and the ability to add a correlative value
case
"a"
:
case
"e"
:
case
"i"
:
case
"o"
:
case
"n"
:
case
"r"
:
case
"t"
:
case
"l"
:
case
"s"
:
case
"u"
:
total
=
total
+
1
;
break
;
case
"d"
:
case
"g"
:
total
=
total
+
2
;
break
;
case
"b"
:
case
"c"
:
case
"m"
:
case
"p"
:
total
=
total
+
3
;
break
;
case
"f"
:
case
"h"
:
case
"v"
:
case
"w"
:
case
"y"
:
total
=
total
+
4
;
break
;
case
"k"
:
total
=
total
+
5
;
break
;
case
"j"
:
case
"x"
:
total
=
total
+
8
;
break
;
case
"q"
:
case
"z"
:
total
=
total
+
10
;
break
;
}
}
return
total
;
// returns scrabble score in total
}
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'
int
lengthP
=
password
.
length
();
boolean
passwd
=
true
;
boolean
lowerCase
=
false
;
// The booleans are inputed so that the needs for the tests are made
boolean
upperCase
=
false
;
boolean
number
=
false
;
boolean
lengthA
=
false
;
boolean
character
=
true
;
boolean
finalTest
=
false
;
String
test
=
password
;
if
(
lengthP
>=
8
&&
lengthP
<=
16
)
{
// this is inputed so that it is between 8 & 16
lengthA
=
true
;
}
for
(
int
i
=
0
;
i
<
password
.
length
();
i
++)
//for loop to cycle through each character of the given password
{
String
cOne
=
""
;
// used to see the variable when debugging
char
charOne
=
password
.
charAt
(
i
);
// selects the letter at the current char placement
Character
special
=
Character
.
toLowerCase
(
charOne
);
//converts character to lowercase
String
dollarTest
=
Character
.
toString
(
charOne
);
//converts character to a string to test for a $
int
speciall
=
(
int
)
special
;
//converts password char to ascii code
if
(!(
speciall
>=
97
&&
speciall
<=
122
||
speciall
>=
48
&&
speciall
<=
57
||
speciall
==
33
||
speciall
==
36
||
speciall
==
37
||
dollarTest
.
equals
(
"$"
)))
// makes sure characters are only the permitted ones
{
finalTest
=
false
;
return
finalTest
;
}
if
(
Character
.
isUpperCase
(
charOne
))
{
// checks for an uppercase character
upperCase
=
true
;
}
if
(
Character
.
isLowerCase
(
charOne
))
// checks for a lowercase character
{
lowerCase
=
true
;
}
if
(
Character
.
isDigit
(
charOne
))
//checks for a digit (number)
{
number
=
true
;
}
if
(
password
.
toLowerCase
().
contains
(
"password"
)
||
password
.
toLowerCase
().
contains
(
"passwd"
))
{
passwd
=
false
;
// converts the passwd to a 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
;
}
}
\ No newline at end of file
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