Commit 5ae8b51d authored by william.leather's avatar william.leather

Replace AssessmentPartTwo.java

parent 01df26df
Pipeline #560 failed with stages
import java.util.regex.Pattern;
public class AssessmentPartTwo {
public class AssessmentPartTwo {
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 // 03 -Scrabble Score
// In scrabble each letter is worth a number of points and each word is worth the // Complete this method so that it returns the scrabble score for the word in aWord
// sum of the scores of the letters in it. For this assignment we will ignore // In scrabble each letter is worth a number of points and each word is worth the
// double/treble letter/word bonuses. // sum of the scores of the letters in it. For this assignment we will ignore
// The English language points per letter can be found at // double/treble letter/word bonuses.
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions // The English language points per letter can be found at
// You will need to come up with a way of connecting each letter to its score and // https://en.wikipedia.org/wiki/Scrabble_letter_distributions
// a way of identifying each letter in the word. // 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.
return 0;
} int finalresult =0;
int i=0;
while(i<aWord.length()-1);
public Boolean passwordValidator(String password) //initiates the loop until the condition is false, to check every single character of the word
{ {
// 04 - Password Validator
// Complete this method to validate that the String password
// is a valid password char letter = aWord.charAt(i);
// A password is valid if it is //letter receives the character from the word, in position i, and treats it similar to an array.
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$% if((letter == 'a') || (letter=='e') || (letter=='i') || (letter=='o') || (letter=='n') || (letter=='r') || (letter=='t') || (letter=='l') || (letter=='s') || (letter=='u'))
// - has at least one lower case letter, one upper case letter and a number {
// - does not contain the phrases 'password' or 'passwd' finalresult=finalresult+1;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
return false; //it will give 1 point
} }
else if ((letter=='d')||(letter=='g'))
} {
finalresult=finalresult+2;
//this goes through these 2 letters mentioned and if the word has ANY of them in it,
//it will give 2 points
}
else if ((letter=='b')||(letter=='c')||(letter=='m')||(letter=='p'))
{
finalresult=finalresult+3;
//this will search through the letters mentioned and if the word has ANY of them in it,
//it will give 3 points
}
else if ((letter=='f')||(letter=='h')||(letter=='v')||(letter=='w')||(letter=='y'))
{
finalresult=finalresult+4;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 4 points
}
else if (letter=='k')
{
finalresult=finalresult+5;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 5 points
}
else if ((letter=='j')||(letter=='x'))
{
finalresult=finalresult+8;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 8 points
}
else if ((letter=='q') || (letter=='z'))
{
finalresult=finalresult+10;
//this will search through letters mentioned and if the word has ANY of them in it,
//it will give 10 points
}
i++;
//goes through to the next letter in the word until it reaches the last letter
}
return finalresult;
//returns the total points for the word
}
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'
Pattern specialCharPatten = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
Pattern UpperCasePatten = Pattern.compile("[A-Z ]");
Pattern lowerCasePatten = Pattern.compile("[a-z ]");
Pattern digitCasePatten = Pattern.compile("[0-9 ]");
//uses the java.util.regex.Pattern from java where it compares every letter of the password
//uses the java.util.regex.Pattern from java to search for upper case
//uses the java.util.regex.Pattern from java to search for lower case
//uses the java.util.regex.Pattern from java to search for numbers and special characters
boolean flag=true;
//turn the final result into a boolean variable to use in every condition
if ((password.length() < 8) && (password.length() >16)) {
flag=false;
//check if password is between 8-16 characters inclusive if not returns false
}
if (!specialCharPatten.matcher(password).find()) {
flag=false;
//search for any special characters and also special words in it for example password
//if not returns false
}
if (!UpperCasePatten.matcher(password).find()) {
flag=false;
//search if password contains upper case if not returns false
}
if (!lowerCasePatten.matcher(password).find()) {
flag=false;
//search if password contains lower case if not returns false
}
if (!digitCasePatten.matcher(password).find()) {
flag=false;
//search if password contains any numbers, if not returns false
}
return flag;
//returns the final result if password is valid or not
}
}
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