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

Update AssessmentPartTwo.java

parent a607aa3a
public class AssessmentPartTwo {
public int scrabbleScore(String aWord)
......@@ -14,20 +13,20 @@ public class AssessmentPartTwo {
// 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.
//Setting up the Primitive int data type of sumOfNumbers and setting it's value to 0
//Setting up the Primitive int data type of wordScore and setting it's value to 0
int wordScore = 0;
//Setting Up the int data type variable I to equal 0.
//And stating that for each time i is is less than the string aWord's length length it will convert aWord to lowercase
//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
for (int i=0; i < aWord.length(); i++) {
aWord = aWord.toLowerCase();
//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 equal to on this run through the code
char letterScore = aWord.charAt(i);
//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
// I's position is determined by what it is equal to on this run through the code
char letterpoints = aWord.charAt(i);
//The switch statement is taking in the char letterScore and comparing into the case values
switch (letterScore) {
//The switch statement is taking in the char letterpoints and comparing into the case values
switch (letterpoints) {
case 'a':
case 'e':
case 'i':
......@@ -38,13 +37,13 @@ public class AssessmentPartTwo {
case 's':
case 't':
case 'u':
//If letterScore is equal to any of the cases above then 1 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 1 will be added to the int wordScore
wordScore +=1;
//The break then stops it from running the next case and resumes the program
break;
case 'd':
case 'g':
//If letterScore is equal to any of the cases above then 2 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 2 will be added to the int wordScore
wordScore +=2;
//The break then stops it from running the next case and resumes the program
break;
......@@ -52,7 +51,7 @@ public class AssessmentPartTwo {
case 'c':
case 'm':
case 'p':
//If letterScore is equal to any of the cases above then 3 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 3 will be added to the int wordScore
wordScore +=3;
//The break then stops it from running the next case and resumes the program
break;
......@@ -61,31 +60,31 @@ public class AssessmentPartTwo {
case 'v':
case 'w':
case 'y':
//If letterScore is equal to any of the cases above then 4 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 4 will be added to the int wordScore
wordScore +=4;
//The break then stops it from running the next case and resumes the program
break;
case 'k':
//If letterScore is equal to any of the cases above then 5 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 5 will be added to the int wordScore
wordScore +=5;
//The break then stops it from running the next case and resumes the program
break;
case 'j':
case 'x':
//If letterScore is equal to any of the cases above then 8 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 8 will be added to the int wordScore
wordScore +=8;
//The break then stops it from running the next case and resumes the program
break;
case 'q':
case 'z':
//If letterScore is equal to any of the cases above then 10 will be added to the int wordScore
//If letterpoints is equal to any of the cases above then 10 will be added to the int wordScore
wordScore +=10;
//The break then stops it from running the next case and resumes the program
default: break;
}
}
//Once the program has ran through the code as many times as it needs to it returns the wordScore
//Once the program has run through the code as many times as it needs to it returns the wordScore
return wordScore;
}
......@@ -98,7 +97,7 @@ public class AssessmentPartTwo {
// 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 !£$%
// - 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'
......@@ -108,12 +107,12 @@ public class AssessmentPartTwo {
if (password.length() < 8 || password.length() > 16) {
return false;
}
//This section of the code runs if password is inbetween 8 and 16 characters
//This section of the code runs if the password is between 8 and 16 characters or is equal to 8 or 16
else {
//This section of code creates two diffent booleans called UpperCaseCheck and LowerCaseCheck
//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
//This section of code creates two different 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
boolean UppercaseCheck = password.equals(password.toLowerCase());
//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
//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
boolean LowercaseCheck = password.equals(password.toUpperCase());
//Creates a boolean called numCheck and sets it to 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