7.9 Lab: Decoder part 1 (string comparison) This program will translate known te
ID: 3703663 • 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;
}
}
7.10 Lab: Decoder part 2 (string search)
This program will find known text message abbreviations within a string and translate them to their actual meanings in unabbreviated form.
(1) Implement for Tests 1 & 2:
Use nextLine() with a Scanner object variable to read one line of user input into a String variable.
Then output the line, as shown below.
Example:
(2) Implement for Tests 3 - 5: (Test 5 is a blind test)
Search the user input string (using indexOf()) to find the common abbreviations listed below
and print a list of each found abbreviation along with its decoded meaning.
NOTE: Each abbreviation will appear no more than once in the text.
Example:
Support these abbreviations (searching for them, in the order listed):
BFF -- best friend forever
IDK -- I don't know
JK -- just kidding
LOL -- laughing out loud
TTYL -- talk to you later
import java.util.Scanner;
public class TextMsgDecoder {
public static void main(String[] args) {
/* Type your code here. */
return;
}
}
Explanation / Answer
TextMsgDecoder.java
import java.util.Scanner;
public class TextMsgDecoder {
public static void main(String[] args) {
String IDK = "I don't know";
String JK = "just kidding";
String TMI = "too much information";
String BFF = "best friend forever";
String TTYL = "talk to you later";
System.out.println("Enter text: ");
Scanner scnr = new Scanner(System.in);
String inString = scnr.nextLine();
System.out.print("You entered: ");
System.out.print(inString);
System.out.println();
if (inString.indexOf("BFF") != -1)
System.out.println("BFF: " + BFF);
if (inString.indexOf("IDK") != -1)
System.out.println("IDK: " + IDK);
if (inString.indexOf("JK")!= -1)
System.out.println("JK: " + JK);
if (inString.indexOf("TMI")!= -1)
System.out.println("TMI: " + TMI);
if (inString.indexOf("TTYL")!= -1)
System.out.println("TTYL: " + TTYL);
return;
}
}
Output:
Enter text:
IDK if I'll go. It's my BFF's birthday.
You entered: IDK if I'll go. It's my BFF's birthday.
BFF: best friend forever
IDK: I don't know
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.