7.9 Lab: Decoder part 1 (string comparison) This program will translate known te
ID: 3704080 • Letter: 7
Question
7.9 Lab: Decoder part 1 (string comparison)
This program will translate known text message abbreviations to their actual meanings in unabbreviated form.
(1) Implement for Tests 1 - 3:
Read an input string from the user.
If the user's input string matches a known text message abbreviation,
Output the unabbreviated form
Otherwise output: Unknown.
Support two abbreviations:
LOL -- laughing out loud
IDK -- I don't know
Sample input/output:
(2) Implement for Tests 4 - 6:
Expand to also decode these abbreviations.
BFF -- best friends forever
IMHO -- in my humble opinion
import java.util.Scanner;
public 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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.