Commit a7175211 authored by daniel.parker's avatar daniel.parker

initial.

parent e56f0d16
Pipeline #384 canceled with stages
......@@ -8,8 +8,27 @@ public class AssessmentPartThree {
// - so a becomes b, b becomes c, etc
// If a value of -2 is chosen a becomes y, b becomes z and so on
public char enryptedCharacter(char theChar, int theOffset)
{
public char enryptedCharacter(char theChar, int theOffset) {
char returnChar = theChar;
int x = 0;
String alphabet = "abcdefghijklmnopqrstuvwxyz";
if (Character.isUpperCase(theChar)) {
alphabet = alphabet.toUpperCase();
}
for (int i = 0; i < alphabet.length(); i++) {
char character = alphabet.charAt(i);
if (character == theChar) {
x = i + theOffset;
if (x > 26) {
x = (x - 26);
}
if (x < 0) {
x = (x + 26);
}
returnChar = alphabet.charAt(x);
}
}
// 05 - encryptedCharacter
// Complete this method so that it returns the encrypted character for
// theChar when and offset of theOffset is used
......@@ -17,16 +36,23 @@ public class AssessmentPartThree {
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return 'a';
return returnChar;
}
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";
}
public String encryptedString(String theMessage, int theOffset) {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String codedString = "";
char[] theMessageChars = theMessage.toCharArray();
int x = -1;
for (int i = 0; i < theMessage.length(); i++) {
char character = theMessage.charAt(i);
codedString+=enryptedCharacter(character,theOffset);
//codedString = String.valueOf(theMessageChars);
}
return codedString;
}
}
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