Commit 872aad8c authored by neil.whitehead's avatar neil.whitehead

FINAL

parent 84d2d7e1
import static org.junit.Assert.assertThat; /**
* <b>Assessment</b> part two<br>
import java.util.Arrays; * <b>Created</b> 08/11/18<br>
* <b>Modified</b> 04/01/18<br>
* @author <a href = "mailto:neil.whitehead@yorksj.ac.uk"> Neil Whitehead</a>, <a href = "mailto:a.guest@yorksj.ac.uk">Andrew Guest</a>
*/
public class AssessmentPartTwo public class AssessmentPartTwo
{ {
public static void main(String[] args) /**
{ * Calculates Scrabble score of string. <br>
System.out.println(passwordValidator("lo98passwdiI")); * Assumes that no validation checks are required.
} * @param aWord String
* @return int
*/
public int scrabbleScore(String aWord) public int scrabbleScore(String aWord)
{ {
// 03 -Scrabble Score
// 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
// sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// 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.
int intWordScore = 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}; 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};
...@@ -29,7 +22,6 @@ public class AssessmentPartTwo ...@@ -29,7 +22,6 @@ public class AssessmentPartTwo
aWord = aWord.toLowerCase(); //converts string to lowercase aWord = aWord.toLowerCase(); //converts string to lowercase
char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars
for(int i = 0; i < chaWordArr.length; i++) for(int i = 0; i < chaWordArr.length; i++)
{ {
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration //Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
...@@ -37,27 +29,24 @@ public class AssessmentPartTwo ...@@ -37,27 +29,24 @@ public class AssessmentPartTwo
{ {
continue; continue;
} }
intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr
} }
return intWordScore; return intWordScore;
} }
/**
public static Boolean passwordValidator(String password) //REMEMBER TO TAKE OUT STATIC * Ensures password is valid. <br>
* &bull; must be between 8 and 16 characters long (inclusive)
* &bull; made up of letters (upper or lower), numbers, and the following characters !�$%
* &bull; has at least one lower case letter, one upper case letter and a number
* &bull; does not contain the phrases 'password' or 'passwd'
* @param password String
* @return Boolean
*/
public Boolean passwordValidator(String password)
{ {
// 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'
boolean booUpper = false; //Uppercase present boolean booUpper = false; //Uppercase present
boolean booLower = false; //Lowercase present boolean booLower = false; //Lowercase present
boolean booNum = false; //Number present boolean booNum = false; //Number present
...@@ -68,13 +57,11 @@ public class AssessmentPartTwo ...@@ -68,13 +57,11 @@ public class AssessmentPartTwo
//Password length between 8 and 16 characters //Password length between 8 and 16 characters
if((password.length() < 8) || (password.length() > 16)) if((password.length() < 8) || (password.length() > 16))
{ {
System.out.println(password.length());
return false; return false;
} }
//Password does not contain. . . //Password does not contain. . .
for(int i = 0; i < strMustNotContain.length; i++) for(int i = 0; i < strMustNotContain.length; i++)
//selects banned words from array //selects banned words from array
{ {
...@@ -84,6 +71,7 @@ public class AssessmentPartTwo ...@@ -84,6 +71,7 @@ public class AssessmentPartTwo
} }
} }
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics //Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i < passwordArr.length; i++) for(int i = 0; i < passwordArr.length; i++)
{ {
...@@ -113,9 +101,7 @@ public class AssessmentPartTwo ...@@ -113,9 +101,7 @@ public class AssessmentPartTwo
{ //if password does not contain Num, Upper, or Lower Chars { //if password does not contain Num, Upper, or Lower Chars
return false; return false;
} }
return true;
//FUCK SAKE. LOOK UP REGEXES.
/* Legacy code that I want to keep if I ever look back on this /* Legacy code that I want to keep if I ever look back on this
...@@ -162,6 +148,7 @@ public class AssessmentPartTwo ...@@ -162,6 +148,7 @@ public class AssessmentPartTwo
} }
*/ */
return true; //Could this be achieved using a regex instead?
} }
} }
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