java code Warm up: Text message abbreviation decoder (Java) (1) If a user\'s inp
ID: 3737565 • Letter: J
Question
java code
Warm up: Text message abbreviation decoder (Java)
(1) If a user's input string matches a known text message abbreviation, output the unabbreviated form, else output: Unknown. Support two abbreviations: LOL -- laughing out loud, and IDK -- I don't know. (3 pts)
Sample input/output:
(2) Expand to also decode these abbreviations. (4 pts)
BFF -- best friends forever
IMHO -- in my humble opinion
TMI -- too much information
import java.util.Scanner;
class TextMsgAbbreviation {
public static void main(String[] args) {
/* type your code here */
return;
}
}
Explanation / Answer
TextMsgAbbreviation.java
import java.util.Scanner;
public class TextMsgAbbreviation {
public static void main(String[] args) {
System.out.println("Input an abbreviation:");
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 static 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");
Str = Str.replace("LOL", "laughing out loud");
return Str;
}
}
Output:
Input an abbreviation:
LOL
You entered:LOL
Expanded: laughing out loud
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.