Commit 17068261 authored by Bran's avatar Bran

completed and added new methods because i may have done the old one

wrong
parent e2bbc9f0
Pipeline #583 canceled with stages
...@@ -21,8 +21,53 @@ public class AssessmentPartThree { ...@@ -21,8 +21,53 @@ 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
char[] alphabet = {'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'};
boolean upperChar;
int letterPlace = 0;
String lowerbet = "abcdefghijklmnopqrstuvwxyz"; //creates a string containing all the letter of the alphabet in lowercase upperChar = Character.isUpperCase(theChar);
theChar = Character.toLowerCase(theChar);
for (int i = 0 ; i < alphabet.length; i++)
{
if (theChar == alphabet[i])
{
theOffset = theOffset + i;
break;
}
}
if (Character.isLetter(theChar))
{
if (theOffset < 0)
{
theOffset = theOffset + 26;
}
if (theOffset > alphabet.length)
{
theOffset = theOffset - 26;
}
else
{
theChar = alphabet[theOffset];
}
}
else
{
return theChar;
}
if (upperChar)
{
theChar = Character.toUpperCase(theChar);
}
return theChar;
}
/* String lowerbet = "abcdefghijklmnopqrstuvwxyz"; //creates a string containing all the letter of the alphabet in lowercase
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // creates a string containing all the letters of the alphabet in uppercase String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // creates a string containing all the letters of the alphabet in uppercase
for (int i = 0; i < lowerbet.length(); i++) // creates a for loop that declares a variable called I, then iterates until i is greater than the length of the string lowerbet (in this case it would be 26) for (int i = 0; i < lowerbet.length(); i++) // creates a for loop that declares a variable called I, then iterates until i is greater than the length of the string lowerbet (in this case it would be 26)
...@@ -44,9 +89,11 @@ public class AssessmentPartThree { ...@@ -44,9 +89,11 @@ public class AssessmentPartThree {
} }
char newnumber = theChar; // assigns the value of theChar to newnum char newnumber = theChar; // assigns the value of theChar to newnum
return newnumber; // returns the value of newnum return newnumber; // returns the value of newnum
}
*/
}
...@@ -56,10 +103,23 @@ public class AssessmentPartThree { ...@@ -56,10 +103,23 @@ public class AssessmentPartThree {
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
{ {
// 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
StringBuilder string = new StringBuilder(); //creates an empty StringBuilder called String
String output = "";
for (char letter : theMessage.toCharArray())
{
letter = enryptedCharacter( letter, theOffset);
output = output + letter;
}
return output;
/* StringBuilder string = new StringBuilder(); //creates an empty StringBuilder called String
char j ; // creates an empty char called j char j ; // creates an empty char called j
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" 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"
...@@ -93,11 +153,9 @@ public class AssessmentPartThree { ...@@ -93,11 +153,9 @@ public class AssessmentPartThree {
string.append (j); // returns string with the value of j added too it string.append (j); // returns string with the value of j added too it
} }
return string.toString(); // returns a string containing whatever is stored in the stringbuilder "string" return string.toString(); // returns a string containing whatever is stored in the stringbuilder "string" */
} }
} }
......
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