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

FINAL

parent 84d2d7e1
import static org.junit.Assert.assertThat;
import java.util.Arrays;
/**
* <b>Assessment</b> part two<br>
* <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 static void main(String[] args)
{
System.out.println(passwordValidator("lo98passwdiI"));
}
{
/**
* Calculates Scrabble score of string. <br>
* Assumes that no validation checks are required.
* @param aWord String
* @return int
*/
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 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};
//Scrabble score 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
aWord = aWord.toLowerCase(); //converts string to lowercase
char chaWordArr[] = aWord.toCharArray(); //places string into array as ASCII chars
for(int i = 0; i < chaWordArr.length; i++)
{
......@@ -37,27 +29,24 @@ public class AssessmentPartTwo
{
continue;
}
intWordScore = intWordScore + intScoreArr[(chaWordArr[i]-97)]; //Char's ASCII code - 97 = Char's position in intScoreArr
}
return intWordScore;
}
public static Boolean passwordValidator(String password) //REMEMBER TO TAKE OUT STATIC
{
// 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'
/**
* 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)
{
boolean booUpper = false; //Uppercase present
boolean booLower = false; //Lowercase present
boolean booNum = false; //Number present
......@@ -68,13 +57,11 @@ public class AssessmentPartTwo
//Password length between 8 and 16 characters
if((password.length() < 8) || (password.length() > 16))
{
System.out.println(password.length());
return false;
}
//Password does not contain. . .
//Password does not contain. . .
for(int i = 0; i < strMustNotContain.length; i++)
//selects banned words from array
{
......@@ -84,6 +71,7 @@ public class AssessmentPartTwo
}
}
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for(int i = 0; i < passwordArr.length; i++)
{
......@@ -113,9 +101,7 @@ public class AssessmentPartTwo
{ //if password does not contain Num, Upper, or Lower Chars
return false;
}
//FUCK SAKE. LOOK UP REGEXES.
return true;
/* Legacy code that I want to keep if I ever look back on this
......@@ -161,7 +147,8 @@ 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