Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssessmentP2
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
samuel.boulton
AssessmentP2
Commits
e123482d
Commit
e123482d
authored
Jan 02, 2019
by
samuelboulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished
parent
3a5d33be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
30 deletions
+32
-30
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+32
-30
No files found.
src/AssessmentPartTwo.java
View file @
e123482d
...
...
@@ -3,22 +3,23 @@ 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.
/* 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.
*/
// Declaring the integer 'theWord' for the total score to be checked
int
theWord
=
0
;
// Looping round the length of the word
for
(
int
j
=
0
;
j
<
aWord
.
length
();
j
++)
{
// Putting the string into chars
// Putting the string into char
acter
s
char
parts
=
aWord
.
charAt
(
j
);
// Then checking if the chars match any of these characters
if
(
parts
==
'l'
...
...
@@ -32,14 +33,14 @@ public class AssessmentPartTwo {
||
parts
==
'i'
||
parts
==
'e'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
1
;
}
// Checking if the chars match any of these characters
if
(
parts
==
'g'
||
parts
==
'd'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
2
;
}
// Checking if the chars match any of these characters
...
...
@@ -48,7 +49,7 @@ public class AssessmentPartTwo {
||
parts
==
'm'
||
parts
==
'p'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
3
;
}
// Checking if the chars match any of these characters
...
...
@@ -58,45 +59,46 @@ public class AssessmentPartTwo {
||
parts
==
'w'
||
parts
==
'y'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
4
;
}
// Checking if the chars match any of these characters
if
(
parts
==
'k'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
5
;
}
// Checking if the chars match any of these characters
if
(
parts
==
'j'
||
parts
==
'x'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
8
;
}
// Checking if the chars match any of these characters
if
(
parts
==
'q'
||
parts
==
'z'
)
{
// If the character matches a char
in the string
it adds this score
// If the character matches a char
acter in the if statement then
it adds this score
theWord
+=
10
;
}
}
// return the total of 'theWord'
to compare against the expectedScore
// return the total of 'theWord'
return
theWord
;
}
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'
/* 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'
*/
// Declaring a boolean variable for a true of false output for an if statement
boolean
validator
=
false
;
...
...
@@ -116,8 +118,8 @@ public class AssessmentPartTwo {
if
(
parts
==
'!'
||
parts
==
'�'
||
parts
==
'%'
||
parts
==
'$'
)
// if the if statement is correct the boolean validator becomes true
{
{
// if the if statement is correct the boolean validator becomes true
validator
=
true
;
}
// if statement to make sure that the password doesn't have anymore symbols other than the ones above.
...
...
@@ -164,7 +166,7 @@ public class AssessmentPartTwo {
}
}
// if statement for when the validator turns true
// if statement for when the validator turns true
. Else is become false and returns false
if
(
validator
==
true
)
{
// check to see if the password has this phrase in it
...
...
@@ -173,7 +175,7 @@ public class AssessmentPartTwo {
// check to see if the password has this phrase in it
if
(!
password
.
contains
(
"password"
))
{
// make sure the password is
between
8-16 letters long
// make sure the password is 8-16 letters long
if
(
password
.
length
()
<=
16
&&
password
.
length
()
>=
8
)
{
// if statement to show the password has at least a lower-case letter in it
...
...
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