- #1
obeying
- 8
- 0
Hi everyone, I've been working on this assignment for a few days now with no luck at all. Would anyone be willing to review this code for me and see if I'm even setting it up right? Here are the directions for the assignment.
1) Use scnr.nextLine(); to get a line of user input into a string. Output that line.
2) Expand common text message abbreviations. Output a message for each abbreviation that is expanded, then output the expanded line. Note: Check for abbreviations in the order provided below.
Support these abbreviations (you only need to support these):
BFF -- best friend forever
IDK -- I don't know
JK -- just kidding
TMI -- too much information
TTYL -- talk to you later
End result of the code should look like:
Enter text: IDK how that happened. TTYL.
You entered: IDK how that happened. TTYL.
Replaced "IDK" with "I don't know".
Replaced "TTYL" with "talk to you later".
Expanded: I don't know how that happened. talk to you later.
Code I have so far:
1) Use scnr.nextLine(); to get a line of user input into a string. Output that line.
2) Expand common text message abbreviations. Output a message for each abbreviation that is expanded, then output the expanded line. Note: Check for abbreviations in the order provided below.
Support these abbreviations (you only need to support these):
BFF -- best friend forever
IDK -- I don't know
JK -- just kidding
TMI -- too much information
TTYL -- talk to you later
End result of the code should look like:
Enter text: IDK how that happened. TTYL.
You entered: IDK how that happened. TTYL.
Replaced "IDK" with "I don't know".
Replaced "TTYL" with "talk to you later".
Expanded: I don't know how that happened. talk to you later.
Code I have so far:
Code:
import java.util.Scanner;
public class TextMsgExpander
{
public static void main(String[ ] args)
{
Scanner in;
in = new Scanner(System.in);
String txtMsg,mesg,replaced;
String BFF="best friend forever";
String IDK="i don't know";
String JK=“just kidding“;
String TMI=“too much information“;
String TTYL="talk to you later";
System.out.print("Enter Text :");
txtMsg=sc.nextLine();
System.out.println("You Entered :"+txtMsg);
if(txtMsg.contains("BFF"))
{
txtMsg=txtMsg.replace("BFF",BFF);
System.out.println("Replaced 'BFF' with "+BFF);
}
if(txtMsg.contains("IDK"))
{
txtMsg=txtMsg.replace("IDK",IDK);
System.out.println("Replaced 'IDK' with "+IDK);
}
if(txtMsg.contains(“JK”))
{
txtMsg=txtMsg.replace(“JK”,JK);
System.out.println("Replaced ‘JK’ with "+JK);
}
if(txtMsg.contains("TMI"))
{
txtMsg=txtMsg.replace("TMI",TMI);
System.out.println("Replaced 'TMI' with "+TMI);
}
if(txtMsg.contains("TTYL"))
{
txtMsg=txtMsg.replace("TTYL",TTYL);
System.out.println("Replaced 'TTYL' with "+TTYL);
}
System.out.println("Expanded :"+txtMsg);
}
}