Commit 63fd1950 authored by joseph.jackson1's avatar joseph.jackson1

Delete AssessmentPartTwo.java

parent 3623904b
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.
int score = 0; // Here I'll add up all the points to later return the value of the word
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 8;
int g = 10; // these ints are used to assign a value to each letter
for (int i=0;i<aWord.length();i++){ // goes through the word 1 letter at a time until it's gone through every letter
char letter = aWord.charAt(i); // assigns a variable to the current index of the word
if ((letter == 'a') || (letter == 'e') || (letter == 'i') || (letter == 'o') || (letter == 'n') ||
(letter == 'r') || (letter == 't') || (letter =='l') || (letter == 's') || (letter == 'u') ){
score = score + a;
} // checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'd') || (letter == 'g') ) {
score = score +b;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'b') || (letter == 'c') || (letter == 'm') || (letter == 'p')) {
score = score +c;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'f') || (letter == 'h') || (letter == 'v') || (letter == 'w') || (letter == 'y')) {
score = score+d;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if (letter == 'k') {
score = score + e;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'j') || (letter == 'x')) {
score= score + f;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
else if ((letter == 'q') || (letter == 'z')) {
score = score + g;
}// checks if any of these letters matches the current index and if so adds the correct points to the total score
}
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'
if(password.contains("passwd") || (password.contains("password") || (password.contains("PASSWORD")))){
return false;
}
else if(password.matches("(?=.+\\d)(?=.+[a-z])(?=.+[A-Z])(.{8,16})$")) {
return true;
}
else {
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