Commit 8ad0a751 authored by ash.brett's avatar ash.brett

Update AssessmentPartTwo.java

parent a607aa3a
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.
//Setting up the Primitive int data type of wordScore and setting it's value to 0
//Setting up the Primitive int data type of sumOfNumbers and setting it's value to 0 int wordScore = 0;
int wordScore = 0;
//Setting Up the int data type variable i to equal 0.
//Setting Up the int data type variable I to equal 0. //And stating that for each time i is less than the string aWord's length it will convert aWord to lowercase
//And stating that for each time i is is less than the string aWord's length length it will convert aWord to lowercase for (int i=0; i < aWord.length(); i++) {
for (int i=0; i < aWord.length(); i++) { aWord = aWord.toLowerCase();
aWord = aWord.toLowerCase(); //The Program then creates the primitive data type char called letterpoints and then sets it to equal the char at the position of i in aWord
//The Program then creates the primitive data type char called letterScore and then sets it to equal the char at the position of i in aWord // I's position is determined by what it is equal to on this run through the code
// I's position is determined by what it equal to on this run through the code char letterpoints = aWord.charAt(i);
char letterScore = aWord.charAt(i);
//The switch statement is taking in the char letterpoints and comparing into the case values
//The switch statement is taking in the char letterScore and comparing into the case values switch (letterpoints) {
switch (letterScore) { case 'a':
case 'a': case 'e':
case 'e': case 'i':
case 'i': case 'l':
case 'l': case 'n':
case 'n': case 'o':
case 'o': case 'r':
case 'r': case 's':
case 's': case 't':
case 't': case 'u':
case 'u': //If letterpoints is equal to any of the cases above then 1 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 1 will be added to the int wordScore wordScore +=1;
wordScore +=1; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'd':
case 'd': case 'g':
case 'g': //If letterpoints is equal to any of the cases above then 2 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 2 will be added to the int wordScore wordScore +=2;
wordScore +=2; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'b':
case 'b': case 'c':
case 'c': case 'm':
case 'm': case 'p':
case 'p': //If letterpoints is equal to any of the cases above then 3 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 3 will be added to the int wordScore wordScore +=3;
wordScore +=3; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'f':
case 'f': case 'h':
case 'h': case 'v':
case 'v': case 'w':
case 'w': case 'y':
case 'y': //If letterpoints is equal to any of the cases above then 4 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 4 will be added to the int wordScore wordScore +=4;
wordScore +=4; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'k':
case 'k': //If letterpoints is equal to any of the cases above then 5 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 5 will be added to the int wordScore wordScore +=5;
wordScore +=5; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'j':
case 'j': case 'x':
case 'x': //If letterpoints is equal to any of the cases above then 8 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 8 will be added to the int wordScore wordScore +=8;
wordScore +=8; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program break;
break; case 'q':
case 'q': case 'z':
case 'z': //If letterpoints is equal to any of the cases above then 10 will be added to the int wordScore
//If letterScore is equal to any of the cases above then 10 will be added to the int wordScore wordScore +=10;
wordScore +=10; //The break then stops it from running the next case and resumes the program
//The break then stops it from running the next case and resumes the program default: break;
default: break;
}
} }
} //Once the program has run through the code as many times as it needs to it returns the wordScore
//Once the program has ran through the code as many times as it needs to it returns the wordScore return wordScore;
return wordScore; }
}
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'
//This section states that is the String password is less than 8 or greater than 16 it will return a false boolean result.
//This section states that is the String password is less than 8 or greater than 16 it will return a false boolean result. if (password.length() < 8 || password.length() > 16) {
if (password.length() < 8 || password.length() > 16) { return false;
return false; }
} //This section of the code runs if the password is between 8 and 16 characters or is equal to 8 or 16
//This section of the code runs if password is inbetween 8 and 16 characters else {
else { //This section of code creates two different booleans called UpperCaseCheck and LowerCaseCheck
//This section of code creates two diffent booleans called UpperCaseCheck and LowerCaseCheck //Password will be checked to see if it's equal to it in all lower case if it is the boolean will be set to true
//Password will be checked to see if it's equal to a it in all lower case if it is the boolean will be set to true boolean UppercaseCheck = password.equals(password.toLowerCase());
boolean UppercaseCheck = password.equals(password.toLowerCase()); //Password will be checked to see if it's equal to it in all Uppercase if it is the boolean will be set to true
//Password will be checked to see if it's equal to a it in all Upper case if it is the boolean will be set to true boolean LowercaseCheck = password.equals(password.toUpperCase());
boolean LowercaseCheck = password.equals(password.toUpperCase());
//Creates a boolean called numCheck and sets it to false.
//Creates a boolean called numCheck and sets it to false. boolean numCheck = false;
boolean numCheck = false;
//This Section states that if UpperCaseCheck Or LowercaseCheck is True then the program will return false
//This Section states that if UpperCaseCheck Or LowercaseCheck is True then the program will return false if(UppercaseCheck || LowercaseCheck) {
if(UppercaseCheck || LowercaseCheck) { return false;
return false; }
}
//creates a for loop that repeats for the number of characters in the array
//creates a for loop that repeats for the number of characters in the array char[] Letters = password.toCharArray();
char[] Letters = password.toCharArray(); //This section creates a for loop that goes for the number of characters in the array
//This section creates a for loop that goes for the number of characters in the array for (char i: Letters)
for (char i: Letters) {
{ //This section checks to see if there is a number in the password
//This section checks to see if there is a number in the password if(Character.isDigit(i))
if(Character.isDigit(i)) {
{ //if there is a number then numCheck is set to true
//if there is a number then numCheck is set to true numCheck = true;
numCheck = true; }
} }
} //This section of code states that if numCheck is false then return false for the program
//This section of code states that if numCheck is false then return false for the program if (numCheck == false)
if (numCheck == false) {
{ return false;
return false; }
}
//This section converts password to lower case and says that if the string password contains "passwd" it will return false
//This section converts password to lower case and says that if the string password contains "passwd" it will return false if ( password.toLowerCase().contains("passwd") ) {
if ( password.toLowerCase().contains("passwd") ) {
return false;
return false;
}
}
//This section converts password to lower case and says that if password contains "password" it will return false
//This section converts password to lower case and says that if password contains "password" it will return false if ( password.toLowerCase().contains("password")) {
if ( password.toLowerCase().contains("password")) {
return false;
return false;
}
}
}
} //If no of these conditions have been triggered the proram will return true
//If no of these conditions have been triggered the proram will return true return true;
return true;
}
} }
}
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