Commit 07e98480 authored by Dell's avatar Dell

commit

parent e56f0d16
...@@ -10,23 +10,207 @@ public class AssessmentPartThree { ...@@ -10,23 +10,207 @@ public class AssessmentPartThree {
public char enryptedCharacter(char theChar, int theOffset) public char enryptedCharacter(char theChar, int theOffset)
{ {
// 05 - encryptedCharacter char a=theChar; // store given character
// Complete this method so that it returns the encrypted character for int b=a; // Stores ASCCI of given character
// theChar when and offset of theOffset is used int Add=0; // Add is use to check Offset and ASCII of given number
// So if theChar='m' and theOffset is 3 the method will return 'p'
// Lower case characters remain lower case, upper case remain upper case
// Any other characters are returned unchanged
return 'a'; if(a>='a' && a<='z') // This condition executes when given charcter is a small Alphabet
{
if(theOffset>=0) // This condition will be executed when the given offset is positive
{
Add=b+theOffset; // Add Offset and ASCII of given number
if(Add>122)
{
Add-=122; // Add = Add-122
Add+=96; //then add 96 in it.
a=(char)Add; //and change ASCII into character
}
else
{
b+=theOffset;
a=(char)b;
}
}
else if(theOffset<0) // This condition will be executed when the given offset is Negative
{
Add=b+theOffset;
if(Add<97)
{
Add-=96;
Add+=122;
a=(char)Add;
}
else
{
b+=theOffset;
a=(char)b;
}
}
} // IF #1 End
else if(a>='A' && a<='Z') // This condition executes when given charcter is a Capital Alphabet
{
if(theOffset>=0) // This condition will be executed when the given offset is positive
{
Add=b+theOffset;
if(Add>90)
{
Add-=90;
Add+=64;
a=(char)Add;
}
else
{
b+=theOffset;
a=(char)b;
}
}
else if(theOffset<0) // This condition will be executed when the given offset is Negative
{
Add=b+theOffset;
if(Add<65)
{
Add-=64;
Add+=90;
a=(char)Add;
}
else
{
b+=theOffset;
a=(char)b;
}
}
} // ELSE #1 END
return a;
} }
public String encryptedString(String theMessage, int theOffset) public String encryptedString(String theMessage, int theOffset)
{
String eMessage=""; // Stores Encryptred message
int b; // Stores ASCII of single Character
char a; // Stores single character of String
String s=theMessage;
int Add=0;
for(int i=0;i<s.length();i++) // s.length() counts total charaters in a String and then For loop executes s.length() times
{ {
// 06 - encryptedMessage
// Complete this method so that it uses encryptedCharacter to
// return the encrypted version of theMessage using theOffset
return "Encryptred message"; a=s.charAt( i ); // get specific character from String
b=a;
if(a>='a' && a<='z') // This condition executes when given charcter is a small Alphabet
{
if(theOffset>=0) // This condition will be executed when the given offset is positive
{
Add=b+theOffset; // Add Offset and ASCII of given number
if(Add>122)
{
Add-=122;
Add+=96;
a=(char)Add;
eMessage +=a; // Add new character in a String
}
else
{
b+=theOffset;
a=(char)b;
eMessage +=a;
}
}
else if(theOffset<0) // This condition will be executed when the given offset is Negative
{
Add=b+theOffset;
if(Add<97)
{
Add-=96;
Add+=122;
a=(char)Add;
eMessage +=a;
}
else
{
b+=theOffset;
a=(char)b;
eMessage +=a;
}
}
} // IF #1 End
else if(a>='A' && a<='Z') // ELSE #1 Start
{
if(theOffset>=0) // This condition will be executed when the given offset is Positive
{
Add=b+theOffset;
if(Add>90)
{
Add-=90;
Add+=64; // by this we can get correct ascii for our character
a=(char)Add; // this will change ascii into character.
eMessage +=a; // and store inn eMessage.
}
else
{
b+=theOffset;
a=(char)b;
eMessage +=a;
}
}
else if(theOffset<0) // This condition will be executed when the given offset is Negative
{
Add=b+theOffset;
if(Add<65)
{
Add-=64;
Add+=90;
a=(char)Add;
eMessage +=a;
}
else
{
b+=theOffset;
a=(char)b;
eMessage +=a;
}
} }
} // ELSE #1 END
else if(b==32) // Use to check Space
{
a=(char)32;
eMessage +=a;
}
else // when charcter is not an Alphabet
{
eMessage +=a;
}
} // End For Loop
return eMessage;
}
} }
\ No newline at end of file
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