Commit e9c3cf05 authored by neil.whitehead's avatar neil.whitehead

11:12 26/11/18

parent 01df26df
Pipeline #338 canceled with stages
......@@ -13,9 +13,29 @@ 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.
return 0;
int intWordScore = 0;
int intScoreArr[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
//Scrabble score a b c d e f g h i j k l m n o p q r s t u v w x y z
aWord = aWord.toLowerCase(); //converts string to lowercase
char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars
for(int i = 0; i < chaWordArr.length; i++)
{
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
if((chaWordArr[i] < 97) || (chaWordArr[i] > 122))
{
continue;
}
intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr
}
return intWordScore;
}
public Boolean passwordValidator(String password)
{
......@@ -24,11 +44,66 @@ public class AssessmentPartTwo {
// 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 !£$%
// - 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;
boolean booPasswordLength = false;
boolean booPasswordChars = false;
boolean booPasswordUpper = false;
boolean booPasswordLower = false;
boolean booPasswordNum = false;
boolean booPasswordUpperLowerNum = false;
boolean booPasswordIsPassword = false;
char passwordArr[] = password.toCharArray();
//true == correct, false == incorrect
//Password length between 8 and 16 characters
booPasswordLength = ((password.length() >= 8) && (password.length() <= 16)) ? true : false;
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i < passwordArr.length; i++)
{
//, ,
if((passwordArr[i] >= 48) && (passwordArr[i] <= 57))
{
booPasswordChars = true;
booPasswordNum = true;
}
else if((passwordArr[i] >= 65) && (passwordArr[i] <= 90)) //65 - 90 = A - B
{
booPasswordChars = true;
booPasswordUpper = true;
}
else if((passwordArr[i] >= 97) && (passwordArr[i] <= 122)) // 97 - 122 = a - b
{
booPasswordChars = true;
booPasswordLower = true;
}
else if (passwordArr[i] == 33 || passwordArr[i] == 63 || passwordArr[i] == 36
|| passwordArr[i] == 37) //33 = !, 63 = ?, 36 = $, 37 = %
{
booPasswordChars = true;
}
else
{
booPasswordChars = false;
return false;
}
//FUCK SAKE. LOOK UP REGEXES.
}
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
for(int i = 0; i < passwordArr.length; i++)
return booPasswordChars;
}
}
......@@ -23,7 +23,10 @@ class AssessmentPartTwoTest {
"speaker,13",
"exactly,19",
"xylophone,24",
"application,17"
"application,17",
"123567, 0", //NW not letters test
"rabbit!,10", //NW mixed letters and not letters test
"RaBbIt, 10" //NW mixed case letters
})
void testScrabbleScore(String theWord, int expectedScore) {
assertEquals(expectedScore, test.scrabbleScore(theWord));
......
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