Commit d9c9720f authored by Bran's avatar Bran

updated

parent 5f51bd4c
......@@ -56,33 +56,46 @@ public class AssessmentPartThree {
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
StringBuilder strBuilder = new StringBuilder();
char x ;
// return the encrypted version of theMessage using theOffset
StringBuilder string = new StringBuilder(); //creates an empty StringBuilder called String
char j ; // creates an empty char called j
for (int i = 0; i < theMessage.length(); i++)
for (int i = 0; i < theMessage.length(); i++) // creates a for loop that iterates until i is greater then the length of whatever is stored in the string "theMessage"
{
x = theMessage.charAt(i);
j = theMessage.charAt(i); // makes j equal to the i'th character of theMessage
if (Character.isLetter(x))
{
x = (char) (theMessage.charAt(i) + theOffset);
if ((Character.isLowerCase(theMessage.charAt(i))) && x > 'z' || (Character.isUpperCase(theMessage.charAt(i))) && x > 'Z')))
{
x = (char) (theMessage.charAt(i) + theOffset);
if (Character.isLetter(j)) // if the value assigned to j is a letter runs the following
{
j = (char) (theMessage.charAt(i) + theOffset); // makes j a char equal to the i'th value of theMessage + the value of the offset
}
if ((Character.isLowerCase(theMessage.charAt(i))) && j > 'z')
{
j = (char) (theMessage.charAt(i) - (theOffset - 26));
}
if (Character.isUpperCase(theMessage.charAt(i)) && j > 'Z')
{
j = (char) (theMessage.charAt(i) - (theOffset - 26));
}
if (Character.isUpperCase(theMessage.charAt(i)) && j < 'A')
{
j = (char) (theMessage.charAt(i) + (theOffset + 26));
}
if ((Character.isLowerCase(theMessage.charAt(i)) && < 'a' || (Character.isUpperCase(theMessage.chatTA))
}
}
if ((Character.isLowerCase(theMessage.charAt(i)) && j < 'a'))
{
j = (char) (theMessage.charAt(i) + (theOffset + 26));
}
string.append (j);
}
return string.toString(); // returns a string containing whatever is stored in the stringbuilder "string"
}
......@@ -127,7 +140,7 @@ public class AssessmentPartThree {
*/
}
}
......
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