The program will ask how many string s it should process


Programming Assignment

Overview

Revisiting the ROT13 encryption program, you are going to break the previous version of the program into methods with this additional functionality:

• The program will ask how many String s it should process, between 1 and 10, and store those String s into an array for processing.

• The program will ask for a shifting factor between -25 and +25, which will determine the encryption/decryption shifting instead of the default shifting by 13 of the previous version of the program.

See descriptions of these additional methods later in the assignment for more information.

Assignment

Make sure you fix any issues that may have been present in that version of the assignment.

Public Methods the Program Must Provide

All methods must be implemented as named as as described in order for Web-CAT to be able to test and score them correctly.

Here are the seven methods you need to write in addition to your main () method for this program.

1. public static int getShift()

This method asks the user to enter a shift value between -25 and 25 inclusive, displays a conversion chart for the user to approve, and then returns the shift value only if they approve of the conversion chart that's been displayed. Data validation should occur on the value between -25 and 25.

2. public static void getSentences (String sentences [])

This method displays all of the elements of the array of String data that it receives, line by line (element by element).

4. public static char shiftLetter(char toConvert, int shift)

This method will shift uppercase letters A through Z shift positions upwards or downwards within the uppercase letters; e.g. shiftLetter('A', 27) returns 'B' . The same operation also applies for lowercase letters a through z ; e.g. shiftLetter('b', -3) returns 'y' . All other characters are returned unchanged; i.e. shiftLetter('!', 5) returns '!' .

5. public static String convertSentence (String sentence, int shift)

This method will do the actual conversion of a String of data to its encoded equivalent in 6-character chunks of data and return the new, encoded String . It should call on the shiftLetter() method to do the actual character conversion for each individual character. In other words, individual character conversion should not happen within this method. This method doesn't do any output.

6. public static void displayEncoded (String[] sentences, int shift)

This method will display in encoded format all of the elements of the array of String data that it receives. It will need to call on the method convertSentence() to convert each string before it displays it. Note that the original array should not be modified with encoded data.

7. public static void displayCombined (String[] sentences, int shift)

This method takes an array of String data and combines all of the String s into a single String that is then processed by the convertSentence() method. The method should essentially display the same results as the displayEncoded() method, except that there won't be separate lines of output but rather one large result instead.

Other String things

The only new thing you'll need to be able to do with a String is build a new String from scratch. You can do this by using the concatenation operation in Java, which uses the operator to append char or String data to an existing String.

Using a global private static Scanner

As with program #9, you will want to utilize a private static Scanner variable in this program. Refer back to that assignment for more information on how to implement this kind of Scanner.

Goals

• Repurpose and refactor code you've already written and enhance its functionality. It's possible you may need to rewrite portions of your existing codebase.

• Continue to refine your refactoring skills while adding additional functionality to an existing program.

• Implement a one-dimensional array of String data and practice passing that array to methods.

Class and File Naming

Name your class Encoder.

Points to Think About

• Depending on how you've implemented your code in the previous assignment, you may need to do a little more rewriting of your code as you compartmentalize different portions of the program in methods.

• One thing you may need to adjust is that in the previous program, you may have simply done output with each character as you encountered it and then output a space every 6 characters. For this program, you'll need to modify that code to build a instead of directly doing output.

• Notice as you implement each method that the methods perform small, well-defined tasks and that some of the methods end up calling other methods to help accomplish those tasks.

Testing Your Program

• Web-CAT expects to find all of the seven methods above plus your main () method when it compiles. To prevent errors and allow for testing earlier you can 'stub out' the methods. This usually involves writing the method signature and block and simply returning a dummy value such as 0 for numbers, false for booleans, '!' for char values, and "test" or some other short message for string return values. You can then write the logic and pass the tests on Web-CAT on a per-method basis, rather than all-or-nothing.

• Check out the sample runs at the end of the assignment for examples.

• Remember that the jGRASP Interactions tool is very useful for testing the individual methods without having to implement all of the supporting code. Directions are provided in the previous assignment for using this tool.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: The program will ask how many string s it should process
Reference No:- TGS02722166

Expected delivery within 24 Hours