Commit f0031230 authored by MaximumShast's avatar MaximumShast

e

parent e56f0d16
......@@ -16,17 +16,77 @@ public class AssessmentPartThree {
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// 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
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 a : 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
char Finished = encoded.charAt(0);
//It then returns the char Finished
return Finished;
return 'a';
}
public String encryptedString(String theMessage, int theOffset)
{
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return "Encryptred message";
StringBuilder encoded = new StringBuilder();
//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 (int a=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
char letter = theMessage.charAt(a);
//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);
encoded.append(Result);
}
//This section of the code returns the value of the StringBuilderin 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