Commit f2838112 authored by benn.robinson's avatar benn.robinson

Update AssessmentPartTwo.java

parent b27a60bd
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 aWord // In scrabble each letter is worth a number of points and each word is worth the
// 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 total = 0;
for (int length = 0; length < aWord.length(); length++) // for loop to count up through the word length
return 0; {
} char aChar = aWord.charAt(length); // selects the letter at the current char placement
Character.toString(aChar); // converts to a string value
Character.toLowerCase(aChar); // converts to lowercase so that it matches
public Boolean passwordValidator(String password) switch (String.valueOf(aChar)) { // Allows the selection of the correct string, and the ability to add a correlative value
{
// 04 - Password Validator case "a": case "e": case "i": case "o": case "n": case "r": case "t": case "l": case "s": case "u":
// Complete this method to validate that the String password total = total + 1;
// is a valid password break;
// 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 !�$% case "d": case "g":
// - has at least one lower case letter, one upper case letter and a number total = total + 2;
// - does not contain the phrases 'password' or 'passwd' break;
return false;
} case "b": case "c": case "m": case "p":
total = total + 3;
} break;
case "f": case "h": case "v": case "w": case "y":
total = total + 4;
break;
case "k":
total = total + 5;
break;
case "j": case "x":
total = total + 8;
break;
case "q": case "z":
total = total + 10;
break;
}
}
return total; // returns scrabble score in total
}
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 !£$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
int lengthP = password.length();
boolean passwd = true;
boolean lowerCase = false; // The booleans are inputed so that the needs for the tests are made
boolean upperCase = false;
boolean number = false;
boolean lengthA = false;
boolean character = true;
boolean finalTest = false;
String test = password;
if (lengthP >= 8 && lengthP <=16)
{ // this is inputed so that it is between 8 & 16
lengthA = true;
}
for (int i = 0; i < password.length(); i ++) //for loop to cycle through each character of the given password
{
String cOne= ""; // used to see the variable when debugging
char charOne = password.charAt(i); // selects the letter at the current char placement
Character special = Character.toLowerCase(charOne); //converts character to lowercase
String dollarTest = Character.toString(charOne); //converts character to a string to test for a $
int speciall = (int)special; //converts password char to ascii code
if (!(speciall >= 97 && speciall <= 122 || speciall >= 48 && speciall <= 57
|| speciall == 33 || speciall == 36 || speciall == 37 || dollarTest.equals("$"))) // makes sure characters are only the permitted ones
{
finalTest = false;
return finalTest;
}
if (Character.isUpperCase(charOne))
{ // checks for an uppercase character
upperCase = true;
}
if (Character.isLowerCase(charOne)) // checks for a lowercase character
{
lowerCase = true;
}
if (Character.isDigit(charOne)) //checks for a digit (number)
{
number = true;
}
if (password.toLowerCase().contains("password") || password.toLowerCase().contains("passwd"))
{
passwd = false; // converts the passwd to a lowercase and then checks for the phrases "password"
} // and "passwd" to ensure all combinations of case are covered
}
if (passwd == true && upperCase == true && lowerCase == true && character == true && number == true && lengthA == true)
{
finalTest = true; // if all the loop tests are true then the final result will become true as the password passes
}
return finalTest;
}
}
\ 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