intvalue=0;//The variable value is equalled to 0 as it hasn't found anything yet.
for(intindex=0;index<aWord.length();index++){// The for loop is looping around the String aWord.
charaLetter=aWord.charAt(index);// The letters are stored in a 'char' array.
switch(aLetter){// The 'switch' function allows the program to use different letters when searching for a word.
case'a':
value+=1;// The variable 'value' is connected to number 1. This is also connected to the letter 'A'.
break;// When the program runs and is finding letters to make words, it knows that the letter 'A' is worth 1 point.
case'e':
value+=1;
break;// the break function is used to allow the program to stop at times to find specific words that they are looking for.
case'i':
value+=1;
break;
case'o':
value+=1;
break;
case'n':
value+=1;
break;
case'r':
value+=1;
break;
case't':
value+=1;
break;
case'l':
value+=1;
break;
case's':
value+=1;
break;
case'u':
value+=1;
break;
case'd':
value+=2;
break;
case'g':
value+=2;
break;
case'b':
value+=3;
break;
case'c':
value+=3;
break;
case'm':
value+=3;
break;
case'p':
value+=3;
break;
case'f':
value+=4;
break;
case'h':
value+=4;
break;
case'v':
value+=4;
break;
case'w':
value+=4;
break;
case'y':
value+=4;
break;
case'k':
value+=5;
break;
case'j':
value+=8;
break;
case'x':
value+=8;
break;
case'q':
value+=10;
break;
case'z':
value+=10;
break;
}
}
returnvalue;// It is returning the variable 'value' as its the variable that is associated with the letters and is calculating the overall score for that word.
}
// 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
...
@@ -13,12 +110,6 @@ public class AssessmentPartTwo {
...
@@ -13,12 +110,6 @@ public class AssessmentPartTwo {
// 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.
return0;
}
publicBooleanpasswordValidator(Stringpassword)
{
// 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
...
@@ -28,7 +119,78 @@ public class AssessmentPartTwo {
...
@@ -28,7 +119,78 @@ public class AssessmentPartTwo {
// - 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'
returnfalse;
publicBooleanpasswordValidator(Stringpassword)
{
String[]list={"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"};//Capitals letters are stored in a String
for(StringlistItem:list){// In the for loop, the capitals string is being transfered to the for loop string.
if(password==listItem){// The selection statement is making the decision on whether the variable 'password' meets the String.
returntrue;// If it matches, it will output true.
}
else{
returnfalse;// If it doesn't match, it will return false.
}
}
}
String[]number={"0","1","2","3","4","5","6","7","8","9"};// The String number is holding the numbers 0-9.
for(StringnumItem:number){// it is then passed to another String called 'numItem'.
if(password==numItem){// The selection statement is making the decision on if the String password matches numItem.
returnfalse;// it will return false if the password contains over more than 1 number.
}
else
{
returntrue;// it will also return true if the password has 1 number in the password.
}
}
String[]lower={"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"};//The String 'lower' is storing the lower case letters in an array.
for(StringlowItem:lower){//It is then passed to the String called lowItem.
if(password==lowItem){// The selection statement is comparing the String password to lowItem.
returnfalse;// It will return false if the password has more than one lower case letter.
}
else{
returntrue;// It will return true if the password has one lower case letter.
}
}
String[]symbol={"!","ï","¿","½","$","%"};// String symbol holds the unique symbols in an array.
for(StringsymItem:symbol){// It is being passed to another String called symItem.
if(password==symItem){// In the selection statement, it is making the decision on whether the String password matches symItem.
returnfalse;// It will return false if the password has more than 1 symbol.
}
else{
returntrue;// It will return true if the password has 1 symbol.
}
}
if(password.length()<8||password.length()>16)// the selection statement is saying that, if the password less than 8 and greater than 16,it will reutrn false.
{
returnfalse;// if the password is within the lengths, it will output true.