Commit e582fccf authored by Dell's avatar Dell

commit

parent 01df26df
import java.util.Scanner;
public class AssessmentPartTwo { public class AssessmentPartTwo {
...@@ -12,13 +13,62 @@ public class AssessmentPartTwo { ...@@ -12,13 +13,62 @@ public class AssessmentPartTwo {
// https://en.wikipedia.org/wiki/Scrabble_letter_distributions // 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 // 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.
int value=0;
for(int i=0;i<aWord.length();i++) // Loop according to the length of "aWord" size.
{
switch(aWord.charAt(i)) // Switch statemant stars.
{
case 'a': case 'e': case 'i': case 'o': case 'n': case 'r': case 't': case 'l': case 's': case 'u': //It will add '1' into value,if you use any alphabets of these.
value=value + 1;
break;
case 'd': case 'g': //It will add '2' into value,if you use any alphabets of these.
value=value+2;
break;
case 'b': case 'c': case 'm': case 'p': //It will add '3' into value,if you use any alphabets of these.
value=value+3;
break;
case 'f':
case 'h':
case 'v':
case 'w':
case 'y': //It will add '4' into value,if you use any alphabets of these.
value=value+4;
break;
case 'k': // '5' for k.
value=value+5;
break;
case 'j': case 'x': // //It will add '8' into value,if you use any alphabets of these.
value=value+8;
break;
case 'q': case 'z': //It will add '10' into value,if you use any alphabets of these.
value=value+10;
break;
default:
System.out.println("invalid INPUT"); //It will show this message if enter invalid input.
break;
}
}
return 0; return value;
} }
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
...@@ -27,8 +77,66 @@ public class AssessmentPartTwo { ...@@ -27,8 +77,66 @@ public class AssessmentPartTwo {
// - 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'
Boolean pas=false;
int a,b,c,d,e,p,x;
a=b=c=d=e=x=0;
p=1;
return false;
if(password.length()<=16 && password.length()>=8 )//Condition that length should be between 8 and 16 characters long
{
a=1; //if codition is true then 'a=1'.
}
if(password.contains("password") || password.contains("passwd"))//If password contain "password" OR "passwd" then 'p=0'
{
p=0;
}
for(int i=0;i<password.length();i++)
{
char Chharacter=password.charAt(i);
if((Chharacter=='!'||Chharacter=='£'||Chharacter=='$'||Chharacter=='%')||(Chharacter>='a' && Chharacter<='z'
)||(Chharacter>='A' && Chharacter<='Z') ||(Chharacter>='0' && Chharacter<='9')) // if these codition are true then 'x=1'
{
x=1;
}
else //otherwise 'x=0'
{
x=0;
break; //and break the loop.
}
if(Chharacter>='a' && Chharacter<='z') //for lower case letters
{
c=1;
}
if(Chharacter>='A' && Chharacter<='Z') //for upper case letters
{
d=1;
}
if((Chharacter>='0' && Chharacter<='9')) // for numeric values.
{
e=1;
}
}
if(a==1 && c==1 && d==1 && e==1 && p==1 && x==1) // If the all previous conditions are true then "pas=true" and return pas.
{
pas= true;
}
return pas;
} }
}
} \ No newline at end of file
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