Commit e123482d authored by samuelboulton's avatar samuelboulton

finished

parent 3a5d33be
......@@ -3,22 +3,23 @@ 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.
/* 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.
*/
// Declaring the integer 'theWord' for the total score to be checked
int theWord = 0;
// Looping round the length of the word
for(int j = 0; j<aWord.length(); j++)
{
// Putting the string into chars
// Putting the string into characters
char parts = aWord.charAt(j);
// Then checking if the chars match any of these characters
if(parts == 'l'
......@@ -32,14 +33,14 @@ public class AssessmentPartTwo {
|| parts == 'i'
|| parts == 'e')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 1;
}
// Checking if the chars match any of these characters
if(parts == 'g'
|| parts == 'd')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 2;
}
// Checking if the chars match any of these characters
......@@ -48,7 +49,7 @@ public class AssessmentPartTwo {
|| parts == 'm'
|| parts == 'p')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 3;
}
// Checking if the chars match any of these characters
......@@ -58,45 +59,46 @@ public class AssessmentPartTwo {
|| parts == 'w'
|| parts == 'y')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 4;
}
// Checking if the chars match any of these characters
if(parts == 'k')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 5;
}
// Checking if the chars match any of these characters
if(parts == 'j'
|| parts == 'x')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 8;
}
// Checking if the chars match any of these characters
if(parts == 'q'
|| parts == 'z')
{
// If the character matches a char in the string it adds this score
// If the character matches a character in the if statement then it adds this score
theWord += 10;
}
}
// return the total of 'theWord' to compare against the expectedScore
// return the total of 'theWord'
return theWord;
}
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'
/* 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'
*/
// Declaring a boolean variable for a true of false output for an if statement
boolean validator = false;
......@@ -116,8 +118,8 @@ public class AssessmentPartTwo {
if(
parts == '!'|| parts == '�'
|| parts == '%'|| parts == '$')
// if the if statement is correct the boolean validator becomes true
{
{ // if the if statement is correct the boolean validator becomes true
validator = true;
}
// if statement to make sure that the password doesn't have anymore symbols other than the ones above.
......@@ -164,7 +166,7 @@ public class AssessmentPartTwo {
}
}
// if statement for when the validator turns true
// if statement for when the validator turns true. Else is become false and returns false
if(validator == true)
{
// check to see if the password has this phrase in it
......@@ -173,7 +175,7 @@ public class AssessmentPartTwo {
// check to see if the password has this phrase in it
if(!password.contains("password"))
{
// make sure the password is between 8-16 letters long
// make sure the password is 8-16 letters long
if(password.length() <= 16 && password.length() >= 8)
{
// if statement to show the password has at least a lower-case letter in it
......
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