Question
I need to modify the code I have written in this Java program so far. I'm trying to find a way to make my program
I need to modify the code I have written in this Java program so far. I'm trying to find a way to make my program ignore all puncuation and spacing in the sentences which are input. When done, I need my output to look like this:
import java.util.Scanner; public class ROT13 { private static Scanner input = new Scanner ( System.in ); public static void main ( String args[] ) { String[] sentences = new String[5]; getSentences ( sentences ); displayOriginal ( sentences ); displayROT13 ( sentences );
}
/** getSentences from user * * This method allows the user to enter text into each of the * element of the String array that it receives. * * @param sentences An array of String[] data * @return None */ public static void getSentences ( String[] sentences ) { System.out.printf ( " Enter your 5 sentences below: " ); int counter = 1; for ( int x = 0; x ", counter ); sentences[x] = input.nextLine(); counter ++; } }
/** displayOriginal * * This method displays all of the elements of the array of String * data that it receives, line by line (element by element). * * @param sentences An array of String[] data * @return None */ public static void displayOriginal ( String [] sentences ) { System.out.println ( " The original text: " ); for ( int x = 0; x
/** charConvert * * This method will take one char value as a parameter and converts * it to its appropriate ROT13 equivalent. The Return value will be the * new ROT13 char equivalent. * * @param temp A character to convert as a char * @return The new ROT13 equivalent as a char */ public static char charConvert ( char temp ) { char result = '?'; switch ( temp ) {
case 'a': case 'A': result = 'N'; break;
case 'b': case 'B': result = 'O'; break;
case 'c': case 'C': result = 'P'; break;
case 'd': case 'D': result = 'Q'; break;
case 'e': case 'E': result = 'R'; break;
case 'f': case 'F': result = 'S'; break;
case 'g': case 'G': result = 'T'; break;
case 'h': case 'H': result = 'U'; break;
case 'i': case 'I': result = 'V'; break;
case 'j': case 'J': result = 'W'; break;
case 'k': case 'K': result = 'X'; break;
case 'l': case 'L': result = 'Y'; break;
case 'm': case 'M': result = 'Z'; break; case 'n': case 'N': result = 'A'; break;
case 'o': case 'O': result = 'B'; break;
case 'p': case 'P': result = 'C'; break;
case 'q': case 'Q': result = 'D'; break;
case 'r': case 'R': result = 'E'; break;
case 's': case 'S': result = 'F'; break;
case 't': case 'T': result = 'G'; break;
case 'u': case 'U': result = 'H'; break;
case 'v': case 'V': result = 'I'; break;
case 'w': case 'W': result = 'J'; break;
case 'x': case 'X': result = 'K'; break;
case 'y': case 'Y': result = 'L'; break;
case 'z': case 'Z': result = 'M'; break; default: break; } return result; }
/** convertSentence * * This method does the actual conversion of a String of data to its * ROT13 equivalent in 5-character chunks of data. It calls on the * charConvert() method to do the actual character conversion for each * individual character. * * @param sentence A String variable to convert * @return ROT13Group The 5-characters in a group ROT13 result as a String */ public static String convertSentence ( String sentence ) { String ROT13Group = ""; int pos = 0; for ( char temp = 'A'; temp
/** displayROT13 * * This method displays in ROT13 format all of the elements of the * array of String data. It calls on the method convertSentence to convert each string before it displays it. * * * * @param sentences An array of String[] data * @return None */
public static void displayROT13 ( String [] sentences ) { System.out.println ( " The line-by-line ROT13: " ); String one = sentences[0]; String ROT13 = convertSentence ( one ); System.out.println ( ROT13 );
String two = sentences[1]; String ROT13Two = convertSentence ( two ); System.out.println ( ROT13Two );
String three = sentences[2]; String ROT13Three = convertSentence ( three ); System.out.println ( ROT13Three );
String four = sentences[3]; String ROT13Four = convertSentence ( four ); System.out.println ( ROT13Four );
String five = sentences[4]; String ROT13Five = convertSentence ( five ); System.out.println ( ROT13Five ); } }
Enter your 5 sentences below: Sentence 1> ABCDEFGHIJ KLMNOPQRSTUVWYZ Sentence 2> abcdefghijklmnopqrstuvwxyz Sentence 3> ab cd ef gh ij kl mn op qr st uv wx yz Sentence 4> abcdefghijklmnopqrstuvwxyz sentence 5> a!bac#d$eXfag&h*t (j)k_1-m=n+ofPLqJr}s|t\u'v"wSX:y/2 ? The original text : ABCDEFGHIJ K LMNOPORSTUVWXYZ abcdefghijklmnopqrstuvwxyz ab cd ef gh ij kl mn op qr st uv wx yz abcdefghijklmnopqrstuvwxyz a! bac#d$eXfng&h * i (j)k_1-n-n+o(PLqJr)slt\u'v"w; x : y/2? The line-by-line ROT13: NOPQR STUN XYZAB CDEFG HI JKL M NOPQR STUVW XYZAB CDE FG HIJKL M NOPOR STUVW XYZAB CDEFG HIJKL M NOPOR STUN XYZAB CDEFG HI JKL M NOPQR STUVW XYZAB CDE FG HI JKL M upp too yss upp too LLLLL 11111 BB P pk Aaaaa 12345 TT aaaaStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started