Write a program that prompts for a line of text and then transforms the text based on chosen actions. Actions include reversing the text and converting the text to leet-speak. You may be able to imagine extending to other actions such as a pig-latin translator, or encoding or decoding a secret message. Turn in the version specified here before extending Welcome to the Text Converter Available Actions 1337) convert to 1337-speak rev) reverse the string quit) exit the progranm Please enter a string: Hello cs 200. Action (1337, rev, quit): rev 002 Sc olleH Action (1337, rev, quit): reverse again Unrecognized action. 002 Sc olleH Action (1337, rev, quit): rev ?? 11 CS 200. Action (1337, rev, quit): quit See you next time!

Relax

Respuesta :

Answer:

public class TextConverterDemo

{

//Method definition of action1337

public static String action1337(String current)

{

//Replace each L or l with a 1 (numeral one)

 current = current.replace('L', '1');

 current = current.replace('l', '1');

 

 //Replace each E or e with a 3 (numeral three)

 current = current.replace('E', '3');

 current = current.replace('e', '3');

 //Replace each T or t with a 7 (numeral seven)

 current = current.replace('T', '7');

 current = current.replace('t', '7');

 //Replace each O or o with a 0 (numeral zero)

 current = current.replace('O', '0');

 current = current.replace('o', '0');

 

//Replace each S or s with a $ (dollar sign)

 current = current.replace('S', '

Otras preguntas

);

 current = current.replace('s', '

Otras preguntas

);

 return current;

}

//Method definition of actionReverse

//This method is used to reverses the order of

//characters in the current string

public static String actionReverse(String current)

{

 //Create a StringBuilder's object

 StringBuilder originalStr = new StringBuilder();

 //Append the original string to the StribgBuilder's object

 originalStr.append(current);

 //Use reverse method to reverse the original string

 originalStr = originalStr.reverse();

 

 //return the string in reversed order

 return originalStr.toString();

}

//Method definition of main

public static void main(String[] args)

{

    //Declare variables

 String input, action;

 

 //Prompt the input message

 System.out.println("Welcome to the Text Converter.");

 System.out.println("Available Actions:");

 System.out.println("\t1337) convert to 1337-speak");

 System.out.println("\trev) reverse the string");

 System.out.print("Please enter a string: ");

   

 //Create a Scanner class's object

 Scanner scn = new Scanner(System.in);

 

 //Read input from the user

 input = scn.nextLine();

 do

 {

  /*Based on the action the user chooses, call the appropriate

   * action method. If an unrecognized action is entered then

   * the message "Unrecognized action." should be shown on a

   * line by itself and then the user is prompted again just

   * as they were when an action was performed.

   * */

  System.out.print("Action (1337, rev, quit): ");

  action = scn.nextLine();

  if (action.equals("1337"))

  {

   input = action1337(input);

   System.out.println(input);

  } else if (action.equals("rev"))

  {

   input = actionReverse(input);

   System.out.println(input);

  } else if (!action.equals("quit"))

  {

   System.out.println("Unrecognized action.");

  }

 } while (!action.equals("quit"));

 System.out.println("See you next time!");

 scn.close();

}

}

Otras preguntas

Hong went shopping after she woke up. It took Hong 20 minutes to get ready to go shopping. She shopped for 45 minutes and then spent 40 minutes eating a snack.
Describe a diet that can lower your stress level. What does the diet look like? What kinds of foods and drinks are in the diet? What quantities of food are in t
raul deposited $3000 dollars into a bank acount that earned simple interest rate each year. After 3.5 years, he had earned $262.50 in interest. If no money was
if w= the right of a trout, which algebraic expression represents the phrase below the weight of trout multiplied by 7
Why do most large corporations use accrual accounting? to appear more professional It better represents the overall company finances. It provides more detail ab
Which detail shapes the theme that one’s race can place one in a position of great danger in the South Africa of Cry, the Beloved Country?
during the California gold rush of the 1850s some Americans in the eastern part of the united states reached California by sailing all the way around south amer
The sound of thunder from a bolt of lightning was heard 2.6 seconds after the lightning hit, from 895 meters away. What was the speed of sound to the nearest te
I will arise and go now, for always night and day I hear lake water lapping with low sounds by the shore: While I stand on the roadway, or on the pavements gray
Georgia needs to buy flea treatment for her dog. Pet Store 1 is offering the flea treatment for 40 percent off plus an additional 25 percent off their regular p