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 int scrabbleScore(String aWord)
{
public int scrabbleScore(String aWord) {
// 03 -Scrabble Score
// Complete this method so that it returns the scrabble score for the word in aWord
// In scrabble each letter is worth a number of points and each word is worth the
// Complete this method so that it returns the scrabble score for the word in
// 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
// double/treble letter/word bonuses.
// The English language points per letter can be found at
// 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.
return 0;
int score = 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
// Complete this method to validate that the String password
// is a valid password
// A password is valid if it is
// - 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
// - does not contain the phrases 'password' or 'passwd'
return false;
final String PASSWORD_= "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,16})";
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