Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am needing help writing a method in my Java program. It is named convertSentence and its specifications are listed towards the end of my

I am needing help writing a method in my Java program. It is named convertSentence and its specifications are listed towards the end of my program below. This method needs to take a String and then use the charConvert() method to create a new String result that is the ROT13 equivalent of what came in.

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 ); }

/** 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 < sentences.length; x++ ) { System.out.printf ( "Sentence %d> ", 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 < sentences.length; x++ ) { System.out.println ( sentences[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 = '?'; if ( ( temp == 'a' ) || ( temp == 'A' ) ) result = 'N';

if ( ( temp == 'b' ) || ( temp == 'B' ) ) result = 'O';

if ( ( temp == 'c' ) || ( temp == 'C' ) ) result = 'P';

if ( ( temp == 'd' ) || ( temp == 'D' ) ) result = 'Q';

if ( ( temp == 'e' ) || ( temp == 'E' ) ) result = 'R';

if ( ( temp == 'f' ) || ( temp == 'F' ) ) result = 'S';

if ( ( temp == 'g' ) || ( temp == 'G' ) ) result = 'T';

if ( ( temp == 'h' ) || ( temp == 'H' ) ) result = 'U';

if ( ( temp == 'i' ) || ( temp == 'I' ) ) result = 'V';

if ( ( temp == 'j' ) || ( temp == 'J' ) ) result = 'W';

if ( ( temp == 'k' ) || ( temp == 'K' ) ) result = 'X';

if ( ( temp == 'l' ) || ( temp == 'L' ) ) result = 'Y';

if ( ( temp == 'm' ) || ( temp == 'M' ) ) result = 'Z';

if ( ( temp == 'n' ) || ( temp == 'N' ) ) result = 'A';

if ( ( temp == 'o' ) || ( temp == 'O' ) ) result = 'B';

if ( ( temp == 'p' ) || ( temp == 'P' ) ) result = 'C';

if ( ( temp == 'q' ) || ( temp == 'Q' ) ) result = 'D';

if ( ( temp == 'r' ) || ( temp == 'R' ) ) result = 'E';

if ( ( temp == 's' ) || ( temp == 'S' ) ) result = 'F';

if ( ( temp == 't' ) || ( temp == 'T' ) ) result = 'G';

if ( ( temp == 'u' ) || ( temp == 'U' ) ) result = 'H';

if ( ( temp == 'v' ) || ( temp == 'V' ) ) result = 'I';

if ( ( temp == 'w' ) || ( temp == 'W' ) ) result = 'J';

if ( ( temp == 'x' ) || ( temp == 'X' ) ) result = 'K';

if ( ( temp == 'y' ) || ( temp == 'Y' ) ) result = 'L';

if ( ( temp == 'z' ) || ( temp == 'Z' ) ) result = 'M'; 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. In other words, individual character conversion should not happen within this method. * * @param sentence A String variable to convert * @return ROT13 The 5-characters in a group ROT13 result as a String */

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

Explain, in your own words, what is meant by source inspection.

Answered: 1 week ago