Commit e52b3223 authored by samuelboulton's avatar samuelboulton

comment added

parent 01df26df
Pipeline #370 failed with stages
...@@ -13,7 +13,77 @@ public class AssessmentPartTwo { ...@@ -13,7 +13,77 @@ 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; // Declaring the integer 'theWord' for the total score to be checked
int theWord = 0;
// Looping round the length of the word
for(int j = 0; j<aWord.length(); j++)
{
// Putting the string into chars
char parts = aWord.charAt(j);
// Then checking if the chars match any of these characters
if(parts == 'l'
|| parts == 's'
|| parts == 'u'
|| parts == 'n'
|| parts == 'r'
|| parts == 't'
|| parts == 'o'
|| parts == 'a'
|| parts == 'i'
|| parts == 'e')
{
// If the character matches a char in the string it adds this score
theWord += 1;
}
// Checking if the chars match any of these characters
if(parts == 'g'
|| parts == 'd')
{
// If the character matches a char in the string it adds this score
theWord += 2;
}
// Checking if the chars match any of these characters
if(parts == 'b'
|| parts == 'c'
|| parts == 'm'
|| parts == 'p')
{
// If the character matches a char in the string it adds this score
theWord += 3;
}
// Checking if the chars match any of these characters
if(parts == 'f'
|| parts == 'h'
|| parts == 'v'
|| parts == 'w'
|| parts == 'y')
{
// If the character matches a char in the string it adds this score
theWord += 4;
}
// Checking if the chars match any of these characters
if(parts == 'k')
{
// If the character matches a char in the string it adds this score
theWord += 5;
}
// Checking if the chars match any of these characters
if(parts == 'j'
|| parts == 'x')
{
// If the character matches a char in the string it adds this score
theWord += 8;
}
// Checking if the chars match any of these characters
if(parts == 'q'
|| parts == 'z')
{
// If the character matches a char in the string it adds this score
theWord += 10;
}
}
// return the total of 'theWord' to compare against the expectedScore
return theWord;
} }
...@@ -24,11 +94,55 @@ public class AssessmentPartTwo { ...@@ -24,11 +94,55 @@ public class AssessmentPartTwo {
// is a valid password // is a valid password
// A password is valid if it is // A password is valid if it is
// - between 8 and 16 characters long (inclusive) // - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !£$% // - 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 // - 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'
// Declaring each String for which is allowed and which isn't allowed
// .matches() is used to see if the password matches these statements
String lowerCase = "(.*[a-z].*)";
String upperCase = ".*[A-Z].*";
String numbers = ".*[0-9].*";
String symbols = ".*[!�$%].*";
// if statement and contains() method to see if the password contains these phrases
if(password.contains("passwd"))
{
return false; return false;
} }
// if statement and contains() method to see if the password contains these phrases
if(password.contains("password"))
{
return false;
}
// if statement to make sure the length is between 16 and 8 letters long
if(password.length() > 16 || password.length() < 8)
{
return false;
}
// if statement to see if there is a lower cased letter in the password
if(!password.matches(lowerCase))
{
return false;
}
// if statement to see if there is a upper cased letter in the password
if(!password.matches(upperCase))
{
return false;
}//hello
// if statement to see if there is a number in the password
if(!password.matches(numbers))
{
return false;
}
if(password.contains("!") || password.contains("�") || password.contains("$") || password.contains("%"))
{
return true;
}
else
{
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