Commit e123482d authored by samuelboulton's avatar samuelboulton

finished

parent 3a5d33be
...@@ -3,22 +3,23 @@ public class AssessmentPartTwo { ...@@ -3,22 +3,23 @@ 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 aWord
// In scrabble each letter is worth a number of points and each word is worth the 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.
*/
// Declaring the integer 'theWord' for the total score to be checked // Declaring the integer 'theWord' for the total score to be checked
int theWord = 0; int theWord = 0;
// Looping round the length of the word // Looping round the length of the word
for(int j = 0; j<aWord.length(); j++) for(int j = 0; j<aWord.length(); j++)
{ {
// Putting the string into chars // Putting the string into characters
char parts = aWord.charAt(j); char parts = aWord.charAt(j);
// Then checking if the chars match any of these characters // Then checking if the chars match any of these characters
if(parts == 'l' if(parts == 'l'
...@@ -32,14 +33,14 @@ public class AssessmentPartTwo { ...@@ -32,14 +33,14 @@ public class AssessmentPartTwo {
|| parts == 'i' || parts == 'i'
|| parts == 'e') || parts == 'e')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 1; theWord += 1;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
if(parts == 'g' if(parts == 'g'
|| parts == 'd') || parts == 'd')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 2; theWord += 2;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
...@@ -48,7 +49,7 @@ public class AssessmentPartTwo { ...@@ -48,7 +49,7 @@ public class AssessmentPartTwo {
|| parts == 'm' || parts == 'm'
|| parts == 'p') || parts == 'p')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 3; theWord += 3;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
...@@ -58,45 +59,46 @@ public class AssessmentPartTwo { ...@@ -58,45 +59,46 @@ public class AssessmentPartTwo {
|| parts == 'w' || parts == 'w'
|| parts == 'y') || parts == 'y')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 4; theWord += 4;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
if(parts == 'k') if(parts == 'k')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 5; theWord += 5;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
if(parts == 'j' if(parts == 'j'
|| parts == 'x') || parts == 'x')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 8; theWord += 8;
} }
// Checking if the chars match any of these characters // Checking if the chars match any of these characters
if(parts == 'q' if(parts == 'q'
|| parts == 'z') || parts == 'z')
{ {
// If the character matches a char in the string it adds this score // If the character matches a character in the if statement then it adds this score
theWord += 10; theWord += 10;
} }
} }
// return the total of 'theWord' to compare against the expectedScore // return the total of 'theWord'
return theWord; return theWord;
} }
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'
*/
// Declaring a boolean variable for a true of false output for an if statement // Declaring a boolean variable for a true of false output for an if statement
boolean validator = false; boolean validator = false;
...@@ -116,8 +118,8 @@ public class AssessmentPartTwo { ...@@ -116,8 +118,8 @@ public class AssessmentPartTwo {
if( if(
parts == '!'|| parts == '�' parts == '!'|| parts == '�'
|| 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; validator = true;
} }
// if statement to make sure that the password doesn't have anymore symbols other than the ones above. // 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 { ...@@ -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) if(validator == true)
{ {
// check to see if the password has this phrase in it // check to see if the password has this phrase in it
...@@ -173,7 +175,7 @@ public class AssessmentPartTwo { ...@@ -173,7 +175,7 @@ public class AssessmentPartTwo {
// check to see if the password has this phrase in it // check to see if the password has this phrase in it
if(!password.contains("password")) 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(password.length() <= 16 && password.length() >= 8)
{ {
// if statement to show the password has at least a lower-case letter in it // if statement to show the password has at least a lower-case letter in it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment