Commit 36c8fc71 authored by simon.nutsey's avatar simon.nutsey

First commit

parent e56f0d16
......@@ -17,7 +17,34 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return 'a';
String Lowcase = "abcdefghijklmnopqrstuvwxyz";
String Upcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // These strings are used to reference if the characeter is lower or uppercase
char out = theChar; //creates an output for the encrypted character
if (Character.isLowerCase(theChar)) { //checks the letter to see if it is lowercase
int index = (Lowcase.indexOf(theChar) + theOffset); //sets the the index of the character
if (index < 0) {
out = Lowcase.charAt(26 + index); //if the index is negative count back from z
} else if (index > 25) {
out = Lowcase.charAt(index - 26); //if the index is more than 25 after z go back to A
} else {
out = Lowcase.charAt(index); //finds the position of the character and then shifts it by the offset value
}
} else if (Character.isUpperCase(theChar)) { //checks the letter to see if it is uppercase
int index = (Upcase.indexOf(theChar) + theOffset);
if (index < 0) {
out = Upcase.charAt(26 + index);//if the index is negative count back from z
} else if (index > 25) {
out = Upcase.charAt(index - 26); //if the index is more than 25 after z go back to A
}else {
out = Upcase.charAt(index); //finds the position of the character and then shifts it by the offset value
}
}
return out;
}
public String encryptedString(String theMessage, int theOffset)
......@@ -26,7 +53,20 @@ public class AssessmentPartThree {
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return "Encryptred message";
char [] outArr = new char [theMessage.length()]; //stores the the encrypted message into char
for (int i = 0; i < theMessage.length(); i++) { //loops through each letter in the string
outArr[i] = enryptedCharacter(theMessage.charAt(i),theOffset);
}
String out = new String(outArr); //converts the char into to string
return out;
}
}
}
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