Create a program using conditional logic and string operatio

Create a program using conditional logic and string operations that does the following using your NetBeans IDE and upload it here:

(1) Use scnr.nextLine(); to get a line of user input into a string. Output that line. (1 pt)

Ex:


(2) Expand common text message abbreviations. Output a message for each abbreviation that is expanded, then output the expanded line. Note: Check for abbreviations in the order provided below. (5 pts)

Support these abbreviations (you only need to support these):

BFF -- best friend forever

IDK -- I don\'t know

JK -- just kidding

TMI -- too much information

TTYL -- talk to you later

Ex:

Solution

TextMsgExpander.java


import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args) {
new TextMsgExpander().run();
}
public void run()
{
System.out.print(\"Enter text:\");
Scanner scnr = new Scanner(System.in);
String inString = scnr.nextLine();
System.out.print(\"You entered:\");
System.out.println(inString);
String message = newMessage(inString);
System.out.println();
if(inString.contains(\"IDK\"))
System.out.println(\"Replaced \\\"IDK\\\" with \\\"I don\'t know\\\".\");
if(inString.contains(\"BFF\"))
System.out.println(\"Replaced \\\"BFF\\\" with \\\"best friend forever\\\".\");
if(inString.contains(\"JK\"))
System.out.println(\"Replaced \\\"JK\\\" with \\\"just kidding\\\".\");
if(inString.contains(\"TMI\"))
System.out.println(\"Replaced \\\"TMI\\\" with \\\"too much information\\\".\");
if(inString.contains(\"TTYL\"))
System.out.println(\"Replaced \\\"TTYL\\\" with \\\"talk to you later\\\".\");
System.out.println();
System.out.println(\"Expanded: \"+message);
}
public String newMessage(String str)
{
String Str = str;
Str = Str.replace(\"BFF\", \"best friend forever\");
Str = Str.replace(\"IDK\", \"I don\'t know\");
Str = Str.replace(\"JK\", \"just kidding\");
Str = Str.replace(\"TMI\", \"too much information\");
Str = Str.replace(\"TTYL\", \"talk to you later\");
return Str;
}
}

Output:

Enter text:IDK how that happened. TTYL.
You entered:IDK how that happened. TTYL.

Replaced \"IDK\" with \"I don\'t know\".
Replaced \"TTYL\" with \"talk to you later\".

Expanded: I don\'t know how that happened. talk to you later.

Create a program using conditional logic and string operations that does the following using your NetBeans IDE and upload it here: (1) Use scnr.nextLine(); to g
Create a program using conditional logic and string operations that does the following using your NetBeans IDE and upload it here: (1) Use scnr.nextLine(); to g

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site