Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assignment 02-18
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
emmanuel.gutzmore
Assignment 02-18
Commits
8db074e2
Commit
8db074e2
authored
Jan 07, 2019
by
Emman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
01df26df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
15 deletions
+67
-15
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+67
-15
No files found.
src/AssessmentPartTwo.java
View file @
8db074e2
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
AssessmentPartTwo
{
public
class
AssessmentPartTwo
{
public
int
scrabbleScore
(
String
aWord
)
public
int
scrabbleScore
(
String
aWord
)
{
{
// 03 -Scrabble Score
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// Complete this method so that it returns the scrabble score for the word in
// In scrabble each letter is worth a number of points and each word is worth the
// 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
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// The English language points per letter can be found at
// 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
score
=
0
;
return
0
;
Set
<
Character
>
visited
=
new
HashSet
<>();
final
Map
<
Character
,
Integer
>
letterScores
=
new
HashMap
<>();
letterScores
.
put
(
'a'
,
1
);
letterScores
.
put
(
'e'
,
1
);
letterScores
.
put
(
'i'
,
1
);
letterScores
.
put
(
'o'
,
1
);
letterScores
.
put
(
'u'
,
1
);
letterScores
.
put
(
'l'
,
1
);
letterScores
.
put
(
'n'
,
1
);
letterScores
.
put
(
'r'
,
1
);
letterScores
.
put
(
's'
,
1
);
letterScores
.
put
(
't'
,
1
);
letterScores
.
put
(
'd'
,
2
);
letterScores
.
put
(
'g'
,
2
);
letterScores
.
put
(
'b'
,
3
);
letterScores
.
put
(
'c'
,
3
);
letterScores
.
put
(
'm'
,
3
);
letterScores
.
put
(
'p'
,
3
);
letterScores
.
put
(
'f'
,
4
);
letterScores
.
put
(
'h'
,
4
);
letterScores
.
put
(
'v'
,
4
);
letterScores
.
put
(
'w'
,
4
);
letterScores
.
put
(
'y'
,
4
);
letterScores
.
put
(
'k'
,
5
);
letterScores
.
put
(
'j'
,
8
);
letterScores
.
put
(
'x'
,
8
);
letterScores
.
put
(
'q'
,
10
);
letterScores
.
put
(
'z'
,
10
);
if
(
null
!=
aWord
&&
!
aWord
.
trim
().
isEmpty
())
{
for
(
int
i
=
0
;
i
<
aWord
.
length
();
i
++)
{
char
ch
=
aWord
.
charAt
(
i
);
score
+=
letterScores
.
get
(
ch
);
visited
.
add
(
ch
);
}
}
return
score
;
}
}
public
Boolean
passwordValidator
(
String
password
)
{
public
Boolean
passwordValidator
(
String
password
)
{
// 04 - Password Validator
// 04 - Password Validator
// Complete this method to validate that the String password
// Complete this method to validate that the String password
// 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'
final
String
PASSWORD_
=
"((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,16})"
;
return
false
;
Pattern
pattern
=
Pattern
.
compile
(
PASSWORD_PATTERN
);
boolean
isValid
=
false
;
if
(
null
!=
password
&&
!
password
.
trim
().
isEmpty
())
{
password
=
password
.
trim
();
if
(!(
password
.
contains
(
"password"
)
||
password
.
contains
(
"passwd"
)))
{
Matcher
matcher
=
pattern
.
matcher
(
password
);
isValid
=
matcher
.
matches
();
}
}
return
isValid
;
}
}
}
}
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