Commit dac1d576 authored by User's avatar User

I have uploaded this file to Gitlab

parent 01df26df
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.
return 0;
public int scrabbleScore(String aWord) {
int value = 0; //The variable value is equalled to 0 as it hasn't found anything yet.
for (int index = 0; index < aWord.length(); index++) {// The for loop is looping around the String aWord.
char aLetter = aWord.charAt(index); // The letters are stored in a 'char' array.
switch (aLetter) {// The 'switch' function allows the program to use different letters when searching for a word.
case 'a':
value += 1; // The variable 'value' is connected to number 1. This is also connected to the letter 'A'.
break; // When the program runs and is finding letters to make words, it knows that the letter 'A' is worth 1 point.
case 'e':
value += 1;
break; // the break function is used to allow the program to stop at times to find specific words that they are looking for.
case 'i':
value += 1;
break;
case 'o':
value += 1;
break;
case 'n':
value += 1;
break;
case 'r':
value += 1;
break;
case 't':
value += 1;
break;
case 'l':
value += 1;
break;
case 's':
value += 1;
break;
case 'u':
value += 1;
break;
case 'd':
value += 2;
break;
case 'g':
value += 2;
break;
case 'b':
value += 3;
break;
case 'c':
value += 3;
break;
case 'm':
value += 3;
break;
case 'p':
value += 3;
break;
case 'f':
value += 4;
break;
case 'h':
value += 4;
break;
case 'v':
value += 4;
break;
case 'w':
value += 4;
break;
case 'y':
value += 4;
break;
case 'k':
value += 5;
break;
case 'j':
value += 8;
break;
case 'x':
value += 8;
break;
case 'q':
value += 10;
break;
case 'z':
value += 10;
break;
}
}
return value; // It is returning the variable 'value' as its the variable that is associated with the letters and is calculating the overall score for that 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.
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'
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'
return false;
}
String[] list = {"A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q","R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; //Capitals letters are stored in a String
for(String listItem : list) { // In the for loop, the capitals string is being transfered to the for loop string.
if(password == listItem) { // The selection statement is making the decision on whether the variable 'password' meets the String.
return true; // If it matches, it will output true.
}
else {
return false;// If it doesn't match, it will return false.
}
}
String[] number = {"0","1","2","3","4","5","6","7","8","9"}; // The String number is holding the numbers 0-9.
for(String numItem : number) { // it is then passed to another String called 'numItem'.
if(password == numItem) { // The selection statement is making the decision on if the String password matches numItem.
return false; // it will return false if the password contains over more than 1 number.
}
else
{
return true; // it will also return true if the password has 1 number in the password.
}
}
String[] lower = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; //The String 'lower' is storing the lower case letters in an array.
for(String lowItem : lower) { //It is then passed to the String called lowItem.
if(password == lowItem) { // The selection statement is comparing the String password to lowItem.
return false; // It will return false if the password has more than one lower case letter.
}
else {
return true; // It will return true if the password has one lower case letter.
}
}
String[] symbol = { "!","ï","¿","½","$","%"}; // String symbol holds the unique symbols in an array.
for(String symItem : symbol) { // It is being passed to another String called symItem.
if(password == symItem) { // In the selection statement, it is making the decision on whether the String password matches symItem.
return false; // It will return false if the password has more than 1 symbol.
}
else {
return true; // It will return true if the password has 1 symbol.
}
}
if(password.length()<8 || password.length()>16) // the selection statement is saying that, if the password less than 8 and greater than 16,it will reutrn false.
{
return false; // if the password is within the lengths, it will output true.
}
else {
return true;// if it isn't, it will 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