I have to Implement a static public method named "encodeCaesar" in the class "Functionality.java", which encodes a text using Caesar encryption and I am a complete novice in Java
Signature: encodeCaesar(String s, int val) : String.
The method gets a string value and an integer value as input parameters. The letters (characters) from the string value are to be shifted by the integer value. For simplicity, I can assume that there are only letters and no spaces, numbers or special characters.
The string value should be converted to lower case before the encryption is performed. The method should return a string where each letter has been moved according to the specified integer value.
Example: encodeCaesar("Ac",3)
returns "df". If the given integer value is less than 0 or greater than 26, an empty string should be returned.
public class Functionality {
public static void main(String[] args) {
}
public static String caesar(String s, int val) {
char[] newString = s.toCharArray();
for(int i = 0; i < s.length(); i++){
int newChar = newString[i]+val;
while(newChar > 65+26) // 65 = A, 26 = number of letters in the alphabet
newChar -= 26;
newString[i] = (char) (newChar);