3.18 Ch 3 Program: Text message expander (Java) (1) Use scnr.nextLine(); to get
ID: 3858816 • Letter: 3
Question
3.18 Ch 3 Program: Text message expander (Java)
(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:
BFF -- best friend forever
IDK -- I don't know
JK -- just kidding
TMI -- too much information
TTYL -- talk to you later
Ex:
Code will be typed in "Type your code here":
import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args) {
/* Type your code here. */
return;
}
}
Explanation / Answer
//Please see the complete code below please do thumbs up if you like the code
package murach.invoice;
import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args) {
/* Type your code here. */
String textMsg;
String BFF="best friend forever";
String IDK="I don't know";
String JK="just kidding";
String TMI="too much information";
String TTYL="talk to you later";
System.out.println("Enter text: ");
Scanner scnr = new Scanner(System.in);
textMsg=scnr.nextLine();
System.out.println("You entered: "+textMsg);
if(textMsg.contains("BFF"))
{
textMsg=textMsg.replace("BFF",BFF);
System.out.println("Replaced "BFF" with "+BFF);
}
if(textMsg.contains("IDK"))
{
textMsg=textMsg.replace("IDK",IDK);
System.out.println("Replaced "IDK" with "+IDK);
}
if(textMsg.contains("JK"))
{
textMsg=textMsg.replace("JK",JK);
System.out.println("Replaced "JK" with "+JK);
}
if(textMsg.contains("TMI"))
{
textMsg=textMsg.replace("TMI",TMI);
System.out.println("Replaced "TMI" with "+TMI);
}
if(textMsg.contains("TTYL"))
{
textMsg=textMsg.replace("TTYL",TTYL);
System.out.println("Replaced "TTYL" with "+TTYL);
}
System.out.println("Expanded: "+textMsg);
}
}
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.