// 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.
// All of the letters and their value.
// A, E, I, O, U, L, N, R, S, T = 1
// D, G = 2
// B, C, M, P = 3
// F, H, V, W, Y = 4
// K = 5
// J, X = 8
// Q, Z = 10
// Is method converts any string into uppercase letters so that it can calculate the score of the word. It turnes lowercase letters into uppercase letters.
aWord=aWord.toUpperCase();
// This method declares that the integer Score is equal to 0.
intScore=0;
// I have used a for loop so that when a word is entered it will star at 0 and continue the loop untill it reaches the end of the length of the word.
for(inti=0;i<aWord.length();i++){
// This line is used to calculate the characters of the variable aWord in the for loop.
charcalculateaWord=aWord(i);
// I have uses a switch statement instead of an If statement becasue i have a large number of possible outcomes and it works with the char primative data type.
switch(calculateaWord){
// If the switch statement is equal to a case then it will execute the case untill a break statement is achived.
case'A':return1;
case'E':return1;
case'I':return1;
case'O':return1;
case'U':return1;
case'L':return1;
case'N':return1;
case'R':return1;
case'S':return1;
case'T':return1;
// The break statement is used to show that teh switch has terminated and the program moves onto the next letter.
break;
case'D':return2;
case'G':return2;
break;
case'B':return3;
case'C':return3;
case'M':return3;
case'P':return3;
break;
case'F':return4;
case'H':return4;
case'V':return4;
case'W':return4;
case'Y':return4;
break;
case'K':return5;
break;
case'J':return8;
case'X':return8;
break;
case'Q':return10;
case'Z':return10;
break;
}
}
// This returnes the total of the score to the console.
returnscore;
}
publicBooleanpasswordValidator(Stringpassword)
{
// 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'
String=password;
// This makes is so that if the password is less than 8 characters it will return as false.
if(password.length()=8){
returnfalse;
}
// This makes is so that if the password is more than 16 characters it will return as false.
if(password.length()=16){
returnfalse;
}
// This CharSequence is used to check that the special characters are in the password.
// It runs an if statement to see if the password string uses one of those 4 characters.
CharSequencespecialCharacter="!�$%"
if(booleantest=String.contains(specialCharacter){
returntrue;
}
// This CharSequence is used to check that the word password is not used in the password.
CharSequencepassword="password"
if(booleantest2=String.contains("password")){
returnfalse;
}
// This CharSequence is used to check that the word passwd is not used in the password.
CharSequencepassword="passwd"
if(booleantest3=String.contains("passwd")){
returnfalse;
}
// This for loop is used to check that the password includes a digit, upper case letter and a lower case letter.
for(inti=0;i<password.length();i++){
if(Character.isDigit(password.charAt(i))){
returntrue;
}
// This else if statement returnes true if there is a lower case letter in the password.