Commit 44c57bf9 authored by Ash's avatar Ash

New Version

parent 01df26df
Pipeline #567 failed with stages
...@@ -3,6 +3,7 @@ public class AssessmentPartTwo { ...@@ -3,6 +3,7 @@ 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
...@@ -13,12 +14,85 @@ public class AssessmentPartTwo { ...@@ -13,12 +14,85 @@ 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.
return 0; //Setting up the Primitive int data type of sumOfNumbers and setting it's value to 0
int wordScore = 0;
//Setting Up the int data type variable I to equal 0.
//And stating that for each time i is is less than the string aWord's length length it will convert aWord to lowercase
for (int i=0; i < aWord.length(); i++) {
aWord = aWord.toLowerCase();
//The Program then creates the primitive data type char called letterScore and then sets it to equal the char at the position of i in aWord
// I's position is determined by what it equal to on this run through the code
char letterScore = aWord.charAt(i);
//The switch statement is taking in the char letterScore and comparing into the case values
switch (letterScore) {
case 'a':
case 'e':
case 'i':
case 'l':
case 'n':
case 'o':
case 'r':
case 's':
case 't':
case 'u':
//If letterScore is equal to any of the cases above then 1 will be added to the int wordScore
wordScore +=1;
//The break then stops it from running the next case and resumes the program
break;
case 'd':
case 'g':
//If letterScore is equal to any of the cases above then 2 will be added to the int wordScore
wordScore +=2;
//The break then stops it from running the next case and resumes the program
break;
case 'b':
case 'c':
case 'm':
case 'p':
//If letterScore is equal to any of the cases above then 3 will be added to the int wordScore
wordScore +=3;
//The break then stops it from running the next case and resumes the program
break;
case 'f':
case 'h':
case 'v':
case 'w':
case 'y':
//If letterScore is equal to any of the cases above then 4 will be added to the int wordScore
wordScore +=4;
//The break then stops it from running the next case and resumes the program
break;
case 'k':
//If letterScore is equal to any of the cases above then 5 will be added to the int wordScore
wordScore +=5;
//The break then stops it from running the next case and resumes the program
break;
case 'j':
case 'x':
//If letterScore is equal to any of the cases above then 8 will be added to the int wordScore
wordScore +=8;
//The break then stops it from running the next case and resumes the program
break;
case 'q':
case 'z':
//If letterScore is equal to any of the cases above then 10 will be added to the int wordScore
wordScore +=10;
//The break then stops it from running the next case and resumes the program
default: break;
}
}
//Once the program has ran through the code as many times as it needs to it returns the wordScore
return wordScore;
} }
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
...@@ -28,7 +102,52 @@ public class AssessmentPartTwo { ...@@ -28,7 +102,52 @@ 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'
return false; //This section states that is the String password is less than 8 or greater than 16 it will return a false boolean result.
if (password.length() < 8 || password.length() > 16) {
return false;
}
//This section of the code runs if password is inbetween 8 and 16 characters
else {
//This section of code creates two diffent booleans called UpperCaseCheck and LowerCaseCheck
//Password will be checked to see if it's equal to a it in all lower case if it is the boolean will be set to true
boolean UppercaseCheck = password.equals(password.toLowerCase());
//Password will be checked to see if it's equal to a it in all Upper case if it is the boolean will be set to true
boolean LowercaseCheck = password.equals(password.toUpperCase());
//This Section states that if UpperCaseCheck Or LowercaseCheck is True then the program will return false
if(UppercaseCheck || LowercaseCheck) {
return false;
}
//This Section creates the string passwd which contains "passwd"
String passwd = "passwd";
//This section converts password to lower case and says that if the string password is equal to passwd or contains passwd then it will return false
if ( password.toLowerCase().indexOf(passwd.toLowerCase()) != -1 ) {
return false;
}
//This Section creates the string passWord which contains "password"
String passWord = "password";
//This section converts password to lower case and says that if the string password is equal to passWord or contains passWord then it will return false
if ( password.toLowerCase().indexOf(passWord.toLowerCase()) != -1 ) {
return false;
}
}
//If no of these conditions have been triggered the proram will return true
return true;
}
} }
}
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