Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3.17 Ch 3 Program: Text message decoder (Java) (1) Use scnr.nextLine() to get a

ID: 3858814 • Letter: 3

Question

3.17 Ch 3 Program: Text message decoder (Java)

(1) Use scnr.nextLine() to get a line of user input into a string. Output the line. (3 pts)

Ex:


(2) Search the string (using indexOf()) for common abbreviations and print a list of each found abbreviation along with its decoded meaning. (3 pts)

Ex:

Support these abbreviations:

BFF -- best friend forever

IDK -- I don't know

JK -- just kidding

TMI -- too much information

TTYL -- talk to you later

Code will be typed in "Type your code here":

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote