I’m studying for my Computer Science class and need an explanation.
To implement a Caesar Cipher translation scheme in Java, you will need to acquire the Key to be used and the text string to be translated. You’ll need to access the characters in the String one-by-one. Use the String.charAt() method to do this. You’ll need to translate each letter using the Key, leaving nonletters alone. You can use the Character.isLetter() method to determine whether a given character is a letter. You’ll need to use exception handling to deal with the case of a nonnumeric Key.
The Key and the String should be on one line, as illustrated. Implement the heart of the program as a method, called “translate.” It should have the following declaration: public static String translate(String inText, int key)
Following is an example of a portion of what your program’s output might look like:
Input key <space> text: 0 AbCd
Input key <space> text: 1 Testing, 1-2-3.
Translated: Uftujoh, 1-2-3.
Input key <space> text: -1 Uftujoh, 1-2-3.
Translated: Testing, 1-2-3.
Input key <space> text: X
Bad key. Not in -3..+3
Input key <space> text: 99
In this assignment, you will build a program that implements the Caesar Cipher algorithm. You must build a method called translate—public static String translate(String inText, int key)—that accepts the provided text and Key. It then uses the Caesar Cipher algorithm to translate inText into a String, called outText, which is what the method returns. If Key is greater than zero, then every character in inText is “shifted” to the right in the alphabet by Key characters. For example, if Key = 1, then “ABC” becomes “BCD.” If key is less than zero, then every character in inText is “shifted” to the left by Key characters. For example, if Key = –2, then “DEF” becomes “BCD.” The key value is guaranteed to be in the range –3..+3.
Translate must be a method with the header/signature shown above.
You also need to build a “driver”—it’s the main method—which does the following:
Note: Translate both encodes(key > 0) and decodes (key < 0)
Complete the following steps to build a program that implements the Caesar Cipher algorithm.
Submit a single .zip file with your Caesar Cipher project files and MS Word screenshot document by 11:59 p.m. on Sunday of this week.