Commit f6841e1b authored by spray's avatar spray

OG upload

parent 01df26df
import java.util.HashMap;
public class AssessmentPartTwo {
......@@ -13,7 +14,44 @@ public class AssessmentPartTwo {
// 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 totalpoints = 0;
HashMap<String, Integer> values= new HashMap<>(); //created a Hashmap to store each letter of the alphabet and their corresponding value
values.put("a", 1); //add a and value to hashmap
values.put("b", 3); //rinse and repeat
values.put("c", 3);
values.put("d", 2);
values.put("e", 1);
values.put("f", 4);
values.put("g", 2);
values.put("h", 4);
values.put("i", 1);
values.put("j", 8);
values.put("k", 5);
values.put("l", 1);
values.put("m", 3);
values.put("n", 1);
values.put("o", 1);
values.put("p", 3);
values.put("q", 10);
values.put("r", 1);
values.put("s", 1);
values.put("t", 1);
values.put("u", 1);
values.put("v", 4);
values.put("w", 4);
values.put("x", 8);
values.put("y", 4);
values.put("z", 10);
String[] splitWord = aWord.split(""); //split the word into chars
for(int i = 0; i < splitWord.length; i++) { //while i < length of word
totalpoints += values.get(splitWord[i]); //total value of the word = itself + next letter value
}
return totalpoints;
}
......@@ -28,7 +66,49 @@ public class AssessmentPartTwo {
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
return false;
int letter = 0; //initialize bunch of variables
int digit = 0;
int upper = 0;
int lower = 0;
int specChar = 1;
char[] pWord = password.toCharArray(); //put the password string into a char array
if(pWord.length >= 8 && pWord.length <= 16) { //if the char array is between 8 and 16
if(password.contains("password")) { //if the password is 'password'
return false; //dont validate
}
if(password.contains("passwd")) { //if the password is 'passwd'
return false; //dont validate
}
for(int i = 0; i <= pWord.length - 1; i++) { //when i is smaller than length of the Char array
//these check if there all of the requirements are met
if(Character.isAlphabetic(pWord[i])) { //if the character is a letter in the alphabet
letter +=1; //add 1 to letter variable
}
if(Character.isDigit(pWord[i])) { //if the character is a number
digit += 1; //add 1 to digit variable
}
if(Character.isUpperCase(pWord[i])) { //if the character is Uppercase
upper += 1; //add 1 to upper variable
}
if(Character.isLowerCase(pWord[i])) { //of the character is Lowercase
lower += 1; //add 1 to lower variable
}
if(pWord[i] == '!' || pWord[i] == '£' || pWord[i] == '$' || pWord[i] == '%') { //if the character is one of the special characters
specChar += 1; //add 1 to specChar variable
}
}
}
if(letter > 0 && digit > 0 && upper > 0 && lower > 0 && specChar > 0) { //if all of the requirements have been met at least once
return true; //validate the password
}
return false; //if non of the conditions are met, return false
}
}
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