Commit c8fa3721 authored by Scourier's avatar Scourier

assessment part two commit

parent 01df26df
......@@ -13,7 +13,41 @@ 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 score = 0; // Here I'll add up all the points to later return the value of the word
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 8;
int g = 10; // these ints are used to assign a value to each letter
for (int i=0;i<aWord.length();i++){ // goes through the word 1 letter at a time until it's gone through every letter
char letter = aWord.charAt(i); // assigns a variable to the current index of the word
if ((letter == 'a') || (letter == 'e') || (letter == 'i') || (letter == 'o') || (letter == 'n') ||
(letter == 'r') || (letter == 't') || (letter =='l') || (letter == 's') || (letter == 'u') ){
score = score + a;
} // checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'd') || (letter == 'g') ) {
score = score +b;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'b') || (letter == 'c') || (letter == 'm') || (letter == 'p')) {
score = score +c;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'f') || (letter == 'h') || (letter == 'v') || (letter == 'w') || (letter == 'y')) {
score = score+d;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if (letter == 'k') {
score = score + e;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'j') || (letter == 'x')) {
score= score + f;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'q') || (letter == 'z')) {
score = score + g;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
}
return score;
}
......@@ -28,7 +62,24 @@ public class AssessmentPartTwo {
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
if(password.contains("passwd") || (password.contains("password") || (password.contains("PASSWORD")))){
return false;
}
else if(password.matches("(?=.+\\d)(?=.+[a-z])(?=.+[A-Z])(.{8,16})$")) {
return true;
}
else {
return false;
}
}
}
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