JAVA! (1) Use scnr.nextLine() to get a line of user input into a string. Output
ID: 3585337 • Letter: J
Question
JAVA!
(1) Use scnr.nextLine() to get a line of user input into a string. Output the line.
Ex:
(2) Copy the method you wrote in Part 1 into the class of Part 2. Search the string (using indexOf()) for common abbreviations and print a list of each abbreviation found along with its decoded meaning. Be sure to use your decoding method from Part 1 to decoded the abbreviations.
Ex:
For abbreviations that occur multiple times, just print it out once.
Ex:
Note: for the tests to pass, you need to handle the abbreviations in the exact order that they are listed below.
Support these abbreviations:
LOL -- laughing out loud
IDK -- I don't know
BFF -- best friends forever
IMHO -- in my humble opinion
TMI -- too much information
HERE is what is correct so far:
import java.util.Scanner;
public class TextMsgDecoder {
/* Add your method from Part 1 here */
public static String decTextAbbr(String textAbbr) {
String IDK = "I don't know";
String TMI = "too much information";
String BFF = "best friends forever";
String IMHO = "in my humble opinion";
String LOL = "laughing out loud";
if(textAbbr.equals("LOL")) {
return LOL;
}
else if(textAbbr.equals("IDK")) {
return IDK;
}
else if(textAbbr.equals("BFF")) {
return BFF;
}
else if(textAbbr.equals("IMHO")) {
return IMHO;
}
else if(textAbbr.equals("TMI")) {
return TMI;
}
else {
return "Unknown";
}
}
public static void main(String[] args) {
Explanation / Answer
TextMsgDecoder.java
import java.util.Scanner;
public class TextMsgDecoder {
public static void main(String[] args) {
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: " + decTextAbbr("BFF"));
if (inString.indexOf("IDK") != -1)
System.out.println("IDK: " + decTextAbbr("IDK"));
if (inString.indexOf("TMI") != -1)
System.out.println("TMI: " + decTextAbbr("TMI"));
if (inString.indexOf("LOL") != -1)
System.out.println("LOL: " + decTextAbbr("LOL"));
if (inString.indexOf("IMHO") != -1)
System.out.println("IMHO: " + decTextAbbr("IMHO"));
return;
}
public static String decTextAbbr(String textAbbr) {
String IDK = "I don't know";
String TMI = "too much information";
String BFF = "best friends forever";
String IMHO = "in my humble opinion";
String LOL = "laughing out loud";
if(textAbbr.equals("LOL")) {
return LOL;
}
else if(textAbbr.equals("IDK")) {
return IDK;
}
else if(textAbbr.equals("BFF")) {
return BFF;
}
else if(textAbbr.equals("IMHO")) {
return IMHO;
}
else if(textAbbr.equals("TMI")) {
return TMI;
}
else {
return "Unknown";
}
}
}
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 friends forever
IDK: I don't know
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.