Commit 51cb1380 authored by Ben's avatar Ben

Third Part Complete

parent e56f0d16
Pipeline #554 canceled with stages
...@@ -17,7 +17,47 @@ public class AssessmentPartThree { ...@@ -17,7 +17,47 @@ 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'; if (Character.isDigit(theChar) || Character.isWhitespace(theChar)) {
return theChar;
}
char[] letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
if (Character.toUpperCase(theChar) == theChar) {
for (int i=0; i<letters.length;i++) {
letters[i] = Character.toUpperCase(letters[i]);
}
}
int index = -1;
for (int i=0; i<letters.length; i++) {
if (theChar == letters[i]) {
index = i;
}
}
if (index != -1) {
if (((index+theOffset) <= letters.length) && (((index + theOffset) >= 0))) {
index = index + theOffset;
}
else if ((index + theOffset) < 0) {
index = letters.length + (index + theOffset);
}
else {
index = (index + theOffset) - letters.length;
}
}
if (index == -1) {
return theChar;
}
else {
return letters[index];
}
} }
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
...@@ -25,8 +65,15 @@ public class AssessmentPartThree { ...@@ -25,8 +65,15 @@ public class AssessmentPartThree {
// 06 - encryptedMessage // 06 - encryptedMessage
// 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
String message = "";
for (int i=0; i<theMessage.length();i++) {
char current = theMessage.charAt(i);
char newChar = enryptedCharacter(current, theOffset);
message = message + newChar;
}
return "Encryptred message"; return message;
} }
} }
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