Commit 8db074e2 authored by Emman's avatar Emman

commit

parent 01df26df
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AssessmentPartTwo { public class AssessmentPartTwo {
public int scrabbleScore(String aWord) public int scrabbleScore(String aWord) {
{
// 03 -Scrabble Score // 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord // Complete this method so that it returns the scrabble score for the word in
// In scrabble each letter is worth a number of points and each word is worth the // aWord
// In scrabble each letter is worth a number of points and each word is worth
// the
// sum of the scores of the letters in it. For this assignment we will ignore // sum of the scores of the letters in it. For this assignment we will ignore
// double/treble letter/word bonuses. // double/treble letter/word bonuses.
// The English language points per letter can be found at // The English language points per letter can be found at
// 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 score = 0;
return 0; Set<Character> visited = new HashSet<>();
final Map<Character, Integer> letterScores = new HashMap<>();
letterScores.put('a', 1);
letterScores.put('e', 1);
letterScores.put('i', 1);
letterScores.put('o', 1);
letterScores.put('u', 1);
letterScores.put('l', 1);
letterScores.put('n', 1);
letterScores.put('r', 1);
letterScores.put('s', 1);
letterScores.put('t', 1);
letterScores.put('d', 2);
letterScores.put('g', 2);
letterScores.put('b', 3);
letterScores.put('c', 3);
letterScores.put('m', 3);
letterScores.put('p', 3);
letterScores.put('f', 4);
letterScores.put('h', 4);
letterScores.put('v', 4);
letterScores.put('w', 4);
letterScores.put('y', 4);
letterScores.put('k', 5);
letterScores.put('j', 8);
letterScores.put('x', 8);
letterScores.put('q', 10);
letterScores.put('z', 10);
if (null != aWord && !aWord.trim().isEmpty()) {
for (int i = 0; i < aWord.length(); i++) {
char ch = aWord.charAt(i);
score += letterScores.get(ch);
visited.add(ch);
}
}
return score;
} }
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
// 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'
final String PASSWORD_= "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,16})";
return false; Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
boolean isValid = false;
if (null != password && !password.trim().isEmpty()) {
password = password.trim();
if (!(password.contains("password") || password.contains("passwd"))) {
Matcher matcher = pattern.matcher(password);
isValid = matcher.matches();
}
}
return isValid;
} }
} }
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