@@ -16,17 +16,77 @@ public class AssessmentPartThree {
...
@@ -16,17 +16,77 @@ public class AssessmentPartThree {
// So if theChar='m' and theOffset is 3 the method will return 'p'
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
// Any other characters are returned unchanged
//This segment of the code creates a new instance of the StringBuilder called encoded for ease of access and fulfilment of the task
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(chara:letter.toCharArray()){
//this states that if the char i is a letter then it will run the following code
if(Character.isLetter(a)){
//this code checks to see if the character is upper case and if it is it then proceeds to work out the new letter once this is done it adds it to the StringBuilder Encoded
if(Character.isUpperCase(a)){
encoded.append((char)('G'+(a-'G'+theOffset)%26));
//This code then runs if the character is a letter but isn't upper case therefore meaning it must be lower case, it proceeds to work out the new letter and then adds it to the StringBuilder Encoded
}else{
encoded.append((char)('g'+(a-'g'+theOffset)%26));
}
//If i isn't a letter then it will run this code
}else{
//this adds the char i to the StringBuilder Encoded
encoded.append(a);
}
}
//This section creates a char called Finished and sets it to equal the first value of the StringBuilder encoded
// Complete this method so that it uses encryptedCharacter to
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
// return the encrypted version of theMessage using theOffset
return"Encryptred message";
StringBuilderencoded=newStringBuilder();
//The area of the code creates the integer a and sets its value to 0. And then says for each time a is less than the length of the String theMessage run the code below and increment i by one
for(inta=0;a<theMessage.length();a++){
//this sets the integer 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(a);
//This section of code takes in the char letter and theOffset in order to run the method enryptedCharacter using these values