Commit 229b95af authored by Ash's avatar Ash

New Version

parent e56f0d16
Pipeline #568 failed with stages
...@@ -17,7 +17,40 @@ public class AssessmentPartThree { ...@@ -17,7 +17,40 @@ public class AssessmentPartThree {
// 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
return 'a';
//This section of the code creates a new instance of StringBuilder called encoded
StringBuilder encoded = new StringBuilder();
//This section of the code creates a new string which is equal the value of theChar
String letter=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 (char i : 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
char Finished = encoded.charAt(0);
//It then returns the char Finished
return Finished;
} }
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
...@@ -26,7 +59,29 @@ public class AssessmentPartThree { ...@@ -26,7 +59,29 @@ public class AssessmentPartThree {
// 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"; //This section of the code creates a new instance of StringBuilder called encoded
StringBuilder encoded = new StringBuilder();
//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 (int i=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
char letter = 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
char Result = this.enryptedCharacter(letter, theOffset);
//This section of code takes in the char Result and adds it to the stringBuilder encoded
encoded.append(Result);
} }
//This section of the code returns the value of the stringBuilder encoded in a string
return encoded.toString();
}
}
}
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