Need Help Fixing the issues to this JAVA code Current Code: import java.util.Sca
ID: 3781956 • Letter: N
Question
Need Help Fixing the issues to this JAVA code
Current Code:
import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args)
{
//Declaring String variables
String txtMsg,mesg,replaced ;
//Scanner Object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
String BFF="best friend forever";
String IDK="I don't know.";
String TMI="Too much information";
String LOL="Laughing out loud";
String IMHO="In my honest opinion";
String TTYL="talk to you later.";
//Getting the inputs entered by the user.
System.out.println("Enter text: ");
txtMsg=sc.nextLine();
//Displaying the user entered Input String
System.out.println("You entered: "+txtMsg);
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("BFF"))
{
txtMsg=txtMsg.replace("BFF",BFF);
System.out.println("Replaced 'BFF' with "+BFF);
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("IDK"))
{
txtMsg=txtMsg.replace("IDK","IDK");
System.out.println("Replaced 'IDK' with ""+IDK+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("TMI"))
{
txtMsg=txtMsg.replace("TMI",TMI);
System.out.println("Replaced 'TMI' with ""+TMI+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("LOL"))
{
txtMsg=txtMsg.replace("LOL",LOL);
System.out.println("Replaced 'LOL' with ""+LOL+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("IMHO"))
{
txtMsg=txtMsg.replace("IMHO","IMHO");
System.out.println("Replaced 'IMHO' with ""+IMHO+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("TTYL"))
{
txtMsg=txtMsg.replace("TTYL","TTYL");
System.out.println("Replaced 'TTYL' with ""+TTYL+""");
}
//Displaying the expanded form.
System.out.println("Expanded: "+txtMsg);
}
}
3.15 Program: Text message expander (Java) Create a program using conditional logic and string operations that does the following Instructor notes using your NetBeans IDE and upload it here: While you will be submitting this assignment through (1) Use scnr.nextLine to get a line of user input into a string. Output that line Zybooks, make sure you are still applying appropriate formatting and in-line commenting. (1 pt) Ex: Enter text IDK how that happened. TTYL You entered: IDK how that happened. TTYL (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. (5 pts) 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 laterExplanation / Answer
Just to point out the corrections -
#1 - JK entry missing
#2 - replace method - in some cases, replacing same strings. Example - txtMsg=txtMsg.replace("IMHO","IMHO");
#3 - Minor corrections in printing (sysouts) - corrected it the way compiler expects
TextMsgExpander.java (Corrected Code)
import java.util.Scanner;
public class TextMsgExpander {
public static void main(String[] args)
{
//Declaring String variables
String txtMsg,mesg,replaced ;
//Scanner Object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
String BFF="best friend forever";
String IDK="I don't know";
String TMI="Too much information";
String LOL="Laughing out loud";
String IMHO="In my honest opinion";
String TTYL="talk to you later";
String JK="just kidding";
//Getting the inputs entered by the user.
System.out.print("Enter text: ");
txtMsg=sc.nextLine();
//Displaying the user entered Input String
System.out.println("You entered: "+txtMsg+" ");
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("BFF"))
{
txtMsg=txtMsg.replace("BFF",BFF);
System.out.println("Replaced "BFF" with "+BFF);
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("IDK"))
{
txtMsg=txtMsg.replace("IDK",IDK);
System.out.println("Replaced "IDK" with ""+IDK+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("TMI"))
{
txtMsg=txtMsg.replace("TMI",TMI);
System.out.println("Replaced "TMI" with ""+TMI+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("LOL"))
{
txtMsg=txtMsg.replace("LOL",LOL);
System.out.println("Replaced "LOL" with ""+LOL+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("IMHO"))
{
txtMsg=txtMsg.replace("IMHO",IMHO);
System.out.println("Replaced "IMHO" with ""+IMHO+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("TTYL"))
{
txtMsg=txtMsg.replace("TTYL",TTYL);
System.out.println("Replaced "TTYL" with ""+TTYL+""");
}
// Check whether the entered string contains Particular string or not
if(txtMsg.contains("JK"))
{
txtMsg=txtMsg.replace("JK",JK);
System.out.println("Replaced "JK" with ""+JK+""");
}
//Displaying the expanded form.
System.out.println(" Expanded: "+txtMsg);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.