@@ -17,7 +17,40 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return'a';
//This section of the code creates a new instance of StringBuilder called encoded
StringBuilderencoded=newStringBuilder();
//This section of the code creates a new string which is equal the value of theChar
Stringletter=String.valueOf(theChar);
//This section of the code creates a char called i and converts the string Letter to an array of characters
//i is the selected character of the array
for(chari:letter.toCharArray()){
//this states that if the char i is a letter then it will run the following code
if(Character.isLetter(i)){
//this code checks to see if the character is uppercase and if it is it then proceeds to workout the new letter once this is done it adds it to the stringBuilder Encoded
if(Character.isUpperCase(i)){
encoded.append((char)('A'+(i-'A'+theOffset)%26));
//This code then runs if the character is a letter but isnt uppercase therefore meaning it must be lower case, it proceds to work out the new letter and then adds it to the stringBuilder Encoded
}else{
encoded.append((char)('a'+(i-'a'+theOffset)%26));
}
//If i isnt a letter then it will run this code
}else{
//this adds the char i to the stringbuilder Encoded
encoded.append(i);
}
}
//This section creates a char called Finished and sets it to equal the first value of the stringbuilder encoded
@@ -26,7 +59,29 @@ public class AssessmentPartThree {
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return"Encryptred message";
//This section of the code creates a new instance of StringBuilder called encoded
StringBuilderencoded=newStringBuilder();
//The section of the code creates the int i and sets it value to 0. and then says for each time i is less than length of the String theMessage run the code below and increment i by one
for(inti=0;i<theMessage.length();i++){
//this sets the int theOffset to be equal to theOffset divided by 26 plus 26
theOffset=theOffset%26+26;
//this creates a char called letter and sets it to be equal to theMessage character at i
//i is used to work out the char of the message
//for example if the value of i is 2 then it will look for the character at 2 in the message
charletter=theMessage.charAt(i);
//This creates a new char called result and sets it to be equal to the result of the method enryptedCharacter
//This section of code takes in the char letter and theOffset in order to run the method enryptedCharacter using these values