Question: Java Please / / File: LessNaiveEncryption.java / / Author: / / / / Description: The skeleton of a program that uses split method / /
Java Please File: LessNaiveEncryption.java Author: Description: The skeleton of a program that uses split method and a StringBuilder objects to reverse the letters of each word, but which keeps the order of the words the same. For example: Input : ab hello Output: ba olleh the required import statements import java.util.Scanner; public class LessNaiveEncryption public static void mainString args Setup a scanner object, and receive user's input Scanner keyboard new ScannerSystemin; System.out.printProvide a sentence to encrypt: ; String userInput keyboard.nextLine; Step : use a split method on the String userInput. The argument the split method should be the delimeter Step can be completed in a single line of code. System.out.printThe encrypted sentence is: ; Step a: Refer to the lecture slides, to see how you can tokenize the sentence that you've placed into userInput. You can use a while loop, or a for loop. split method will return an array of Strings tokens Step b: For each token word that you extract from the input sentences, build a StringBuilder object. We learned in lecture that the StringBuilder Class has many useful methods used to manipulate a String. Perform a web search for "Java API", and access the oracle webpage. Click on the StringBuilder class name in the navigation box on the left of the screen, and look for a method that will reverse the String field in the StringBuilder object that you've created. Step c: Use the method that you've found via the API, to reverse the String field in your StringBuilder object, and print that reverse String to the console. Steps a through c can be completed with lines of code. If you used System.out.print when tokenizing your String, the following command will output a final blank line after the last output System.out.print; import java.util.Scanner; File: NaiveEncryption.java Author: Tatiana Harrison Description: An "encryption" program that does not use the split nor StringBuilder classes, but only the types of control structures that you've learned in CS This same functionality can be written in far fewer lines of code if a split and StringBuilder were used. public class NaiveEncryption public static void mainString args setup a scanner object, and receive user's input Scanner keyboard new ScannerSystemin; System.out.printProvide an input sentence: ; String input keyboard.nextLine; System.out.printThe output sentence is : ; String intermediateWord ; for int i ; i input.length; i if inputsubstringi i equalsi input.length if i input.length intermediateWord input.substringi i ; for int j intermediateWord.length; j ; j System.out.printintermediateWordsubstringj j ; intermediateWord ; System.out.print; else intermediateWord input.substringi i ; System.out.println; File: OutrageousCalculations.java Author: Tatiana Harrison Explanation: A 'confusing' program, that lends itself to analysis, using jGRASP's debugger. public class OutrageousCalculations the main routine public static void mainString args int calculatedNumber performOutrageousCalculation; System.out.printlncalculatedNumber: calculatedNumber; int finalCal performAnotherOutrageuosCalccalculatedNumber; System.out.printlnfinalCal: finalCal; a method that has a complex for loop, with an embedded while loop public static int performOutrageousCalculationint m int someNumber m; int anotherNumber ; int j ; for int i k ; i ; i k i i ; j k; anotherNumber
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
