Commit 5028d44d authored by louie.bridges's avatar louie.bridges

Upload New File

parent 24ee13d6
public class AssessmentPartTwo {
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
// 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
// a way of identifying each letter in the word.
// All of the letters and their value.
// A, E, I, O, U, L, N, R, S, T = 1
// D, G = 2
// B, C, M, P = 3
// F, H, V, W, Y = 4
// K = 5
// J, X = 8
// Q, Z = 10
// Is method converts any string into uppercase letters so that it can calculate the score of the word. It turnes lowercase letters into uppercase letters.
aWord = aWord.toUpperCase();
// This method declares that the integer Score is equal to 0.
int Score = 0;
// I have used a for loop so that when a word is entered it will star at 0 and continue the loop untill it reaches the end of the length of the word.
for (int i=0; i<aWord.length(); i++) {
// This line is used to calculate the characters of the variable aWord in the for loop.
char calculateaWord = aWord(i);
// I have uses a switch statement instead of an If statement becasue i have a large number of possible outcomes and it works with the char primative data type.
switch (calculateaWord) {
// If the switch statement is equal to a case then it will execute the case untill a break statement is achived.
case 'A': return 1;
case 'E': return 1;
case 'I': return 1;
case 'O': return 1;
case 'U': return 1;
case 'L': return 1;
case 'N': return 1;
case 'R': return 1;
case 'S': return 1;
case 'T': return 1;
// The break statement is used to show that teh switch has terminated and the program moves onto the next letter.
break;
case 'D': return 2;
case 'G': return 2;
break;
case 'B': return 3;
case 'C': return 3;
case 'M': return 3;
case 'P': return 3;
break;
case 'F': return 4;
case 'H': return 4;
case 'V': return 4;
case 'W': return 4;
case 'Y': return 4;
break;
case 'K': return 5;
break;
case 'J': return 8;
case 'X': return 8;
break;
case 'Q': return 10;
case 'Z': return 10;
break;
}
}
// This returnes the total of the score to the console.
return score ;
}
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'
String = password;
// This makes is so that if the password is less than 8 characters it will return as false.
if (password.length() = 8) {
return false;
}
// This makes is so that if the password is more than 16 characters it will return as false.
if (password.length() = 16) {
return false;
}
// This CharSequence is used to check that the special characters are in the password.
// It runs an if statement to see if the password string uses one of those 4 characters.
CharSequence specialCharacter = "!�$%"
if (boolean test = String.contains(specialCharacter){
return true;
}
// This CharSequence is used to check that the word password is not used in the password.
CharSequence password = "password"
if(boolean test2 = String.contains("password")) {
return false;
}
// This CharSequence is used to check that the word passwd is not used in the password.
CharSequence password = "passwd"
if(boolean test3 = String.contains("passwd")) {
return false;
}
// This for loop is used to check that the password includes a digit, upper case letter and a lower case letter.
for (int i = 0; i < password.length(); i ++) {
if (Character.isDigit(password.charAt(i))) {
return true;
}
// This else if statement returnes true if there is a lower case letter in the password.
else if (Character.isLowerCase(password.charAt(i))) {
return true;
}
// This else if statement returnes true if there is a lower case letter in the password.
else if(Character.isUpperCase(Password.charAt(i))) {
return true;
}
}
}
return password;
}
}
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