Commit 5f51bd4c authored by Bran's avatar Bran

almost complete

parent 51ae5ee1
import java.util.Arrays;
public class AssessmentPartThree { public class AssessmentPartThree {
...@@ -21,92 +22,117 @@ public class AssessmentPartThree { ...@@ -21,92 +22,117 @@ public class AssessmentPartThree {
// Any other characters are returned unchanged // Any other characters are returned unchanged
String lowerbet = "abcdefghijklmnopqrstuvwxyz"; String lowerbet = "abcdefghijklmnopqrstuvwxyz"; //creates a string containing all the letter of the alphabet in lowercase
String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String capitalbet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // creates a string containing all the letters of the alphabet in uppercase
for (int i = 0; i < lowerbet.length();i++)
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)
{ {
if (theChar == lowerbet.charAt(i)); if (theChar == lowerbet.charAt(i)) // creates an if statement that triggers if the character in theChar is equal to the ith value of the string lowerbet
{ {
char newnumber = lowerbet.charAt(theOffset + i); char newnumber = lowerbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of I of the string lowerbet to a char called newnum
return newnumber;
return newnumber; // returns the value of newnum
} }
if (theChar == capitalbet.charAt(i)) if (theChar == capitalbet.charAt(i)) // if the value of theChar is equal to the i'th character of the string capitalbet
{ {
char newnumber = capitalbet.charAt(theOffset + i); // assigns character equal to the character at the value of offset + the value of i
char newnum = lowerbet.charAt(theOffset+i); return newnumber; //returns the value of newnum
}
return newnum;
} }
char newnumber = theChar; // assigns the value of theChar to newnum
return newnumber; // returns the value of newnum
}
char newnumber = theChar;
return newnumber
;
}
}
///////////////////////////////////////////////////////////////////////
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 strBuilder = new StringBuilder();
char x ;
for (int i = 0; i < theMessage.length(); i++)
{ {
// 06 - encryptedMessage x = theMessage.charAt(i);
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
if (Character.isLetter(x))
{ {
// 06 - encryptedMessage x = (char) (theMessage.charAt(i) + theOffset);
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
String alphabeto = "abcdefghijklmnopqrstuvwxyz"; if ((Character.isLowerCase(theMessage.charAt(i))) && x > 'z' || (Character.isUpperCase(theMessage.charAt(i))) && x > 'Z')))
String CAPSalphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char newnum = 0;
char[] theChar = theMessage.toCharArray(); {
x = (char) (theMessage.charAt(i) + theOffset);
for (int x = 0; x < theMessage.length(); x++) { if ((Character.isLowerCase(theMessage.charAt(i)) && < 'a' || (Character.isUpperCase(theMessage.chatTA))
}
}
}
for (int i = 0; i < alphabeto.length(); i++) {
if (theChar[x] == alphabeto.charAt(i)) {
newnum = alphabeto.charAt(theOffset+i);
}
if (theChar[x] == CAPSalphabet.charAt(i)) {
newnum = CAPSalphabet.charAt(theOffset+i);
} /* char[] buffer = theMessage.toCharArray();
for (int i = 0; i < buffer.length; i++)
{
}
theChar[x] = newnum;
System.out.println(theChar[x]);
}
String output = Arrays.toString(theChar);
System.out.println(output);
return "Encryptred message";
char letter = buffer[i];
letter = (char) (letter + theOffset);
if (('z' < letter) && ('Z' < letter))
{
letter = (char) (letter - 26);
} }
else if (('a'< letter) && ('A' < letter))
{
letter = (char) (letter + 26);
} }
else
{
letter = (char) (letter);
}
buffer[i] = letter;
} }
return new String(buffer);
} }
*/
}
}
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