Commit 84c104aa authored by Romain's avatar Romain

final update

parent 83770f73
...@@ -13,17 +13,18 @@ public class AssessmentPartTwo { ...@@ -13,17 +13,18 @@ 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.
int total = 0; int total = 0; //create a variable to store the number of points in a word
int point=0; int point=0; // create a variable to connect each letter to their number of points
boolean to=false; boolean to=false; // Create a boolean to take in account problem in aWord (number, special characters...)
aWord=aWord.toLowerCase(); // to be sure each letter is in the same format before the loop
for (int j=0;j<aWord.length();j++) for (int j=0;j<aWord.length();j++) // Create a loop that run each letter in aWord
{ {
switch(aWord.charAt(j)) switch(aWord.charAt(j)) //Create a switch for each letter in the alphabet and link each letter to their number of points.
{ {
case 'a': case 'o':case 'e':case 'i':case 'n':case 'r':case 't':case 'l':case 's':case 'u': point=1; case 'a': case 'o':case 'e':case 'i':case 'n':case 'r':case 't':case 'l':case 's':case 'u': point=1;
total=total+point; total=total+point; // total take total + the number of point for the letter
break; break;
case 'd':case 'g':point=2; case 'd':case 'g':point=2;
total=total+point; total=total+point;
...@@ -44,18 +45,19 @@ public class AssessmentPartTwo { ...@@ -44,18 +45,19 @@ public class AssessmentPartTwo {
total=total+point; total=total+point;
break; break;
default : default :
to=true; to=true; // if the letter is not a letter
total=0; // total = 0 if something is not a letter in aWord
break; break;
} }
} }
if(to==false) if(to==false) // if all going well
{ {
System.out.print(total); System.out.print(total);
}else }else
{ {
System.out.println("Error"); System.out.println("Error"); // if something is wrong
} }
return total; return total;
} }
...@@ -71,17 +73,19 @@ public class AssessmentPartTwo { ...@@ -71,17 +73,19 @@ 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 pass=false;
boolean valid=false; // create some boolean to check if each condition is ok or not
boolean lowerCase=false; boolean pass=false; // final boolean to store if the password is good or wrong
boolean upperCase=false; boolean valid=false; // boolean to store if the password is between 8 and 16 characters long (inclusive)
boolean number=false; boolean lowerCase=false; // boolean to store if at least one letter is a lower case
boolean test=false; boolean upperCase=false; // boolean to store if at least one letter is a upper case
boolean specialChar=false; boolean number=false; // boolean to store if at least one character is a number
boolean error=false; boolean test=false; // boolean to store the test result
boolean specialChar=false; // boolean to check if a special character is use or not
boolean error=false; // boolean to store if something is wrong
if (password.length()>=8 & password.length()<=16) if (password.length()>=8 & password.length()<=16) // first test for the password length
{ {
valid=true; valid=true;
} }
...@@ -89,31 +93,31 @@ public class AssessmentPartTwo { ...@@ -89,31 +93,31 @@ public class AssessmentPartTwo {
valid=false; valid=false;
} }
for(int i=0;i<password.length();i++) for(int i=0;i<password.length();i++) // loop to run each letter in the password
{ {
if(Character.isLowerCase(password.charAt(i))==true) if(Character.isLowerCase(password.charAt(i))==true) // test if the character is a lower case
{ {
lowerCase=true; lowerCase=true;
}else }else
{ {
if(Character.isUpperCase(password.charAt(i))==true) if(Character.isUpperCase(password.charAt(i))==true) // test if the character is a upper case
{ {
upperCase=true; upperCase=true;
}else }else
{ {
if(Character.isDigit(password.charAt(i))==true) if(Character.isDigit(password.charAt(i))==true) // test if the character is a digit
{ {
number=true; number=true;
}else }else
{ {
switch(password.charAt(i)) switch(password.charAt(i)) // switch to take in account the special character
{ {
case '!' : case '%' : case '$': case '£' : test=true; case '!' : case '%' : case '$': case '£' : test=true;
specialChar=true; specialChar=true;
error=false; error=false;
break; break;
default : test=false; default : test=false; // if password is build with another character than above
error=true; error=true;
break; break;
} }
...@@ -127,12 +131,12 @@ public class AssessmentPartTwo { ...@@ -127,12 +131,12 @@ public class AssessmentPartTwo {
} }
if(password.toLowerCase().contains("password")|password.toLowerCase().contains("passwd")) if(password.toLowerCase().contains("password")|password.toLowerCase().contains("passwd")) // test if the password contains password or passwd
{ {
valid=false; valid=false;
} }
if(lowerCase==true & upperCase==true & valid==true & number==true & error==false) if(lowerCase==true & upperCase==true & valid==true & number==true & error==false) // final condition test
{ {
pass=true; pass=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