3.15 Program: Text message expander (Java)

In summary: The second System.out.println("You entered: "+txtMsg); should beIn summary, Dave replaced "IDK" with "I don't know" and "TTYL" with "talk to you later" in his code.
  • #1
zatawave
2
0
I'm having issues with this code, here are the parameters and results.

Create a program using conditional logic and string operations that does the following using your NetBeans IDE and upload it here:

(1) Use scnr.nextLine(); to get a line of user input into a string. Output that line. (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 later
Ex:

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.

My Code:

Code:
import java.util.Scanner;

public class TextMsgExpander {

   public static void main(String[] args)
   {
       String txtMsg,mesg,replaced ;

        Scanner scnr = 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 humble opinion";
       String TTYL="talk to you later";

       System.out.println("Enter text: ");
       txtMsg=scnr.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("TMI"))
       {
           txtMsg=txtMsg.replace("TMI",TMI);
           System.out.println("Replaced 'TMI' with ""+TMI+""");
       }
         
       if(txtMsg.contains("LOL"))
       {
           txtMsg=txtMsg.replace("LOL",LOL);
           System.out.println("Replaced 'LOL' with ""+LOL+""");
       }
         
       if(txtMsg.contains("IMHO"))
       {
           txtMsg=txtMsg.replace("IMHO",IMHO);
           System.out.println("Replaced 'IMHO' with ""+IMHO+""");
       }
         
       if(txtMsg.contains("TTYL"))
       {
           txtMsg=txtMsg.replace("TTYL",TTYL);
           System.out.println("Replaced 'TTYL' with ""+TTYL+""");
       }
 
        System.out.println("Expanded: "+txtMsg);
    
     return;

Sorry the post is so long, does anyone have any pointers?

Thank you,

Dave
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Your [m]println[/m] statements have different stricture as far as quotation marks go. One is

[m]System.out.println("Replaced 'BFF' with "+BFF);[/m]

and the next is

[m]System.out.println("Replaced 'IDK' with ""+IDK+""");[/m]

Could you explain why you made them different? What is the structure of the second line? For example: This argument of [m]println[/m] is the concatenation of three strings. The first is "Replaced 'IDK' with "; the second is...

And, of course, you code needs two closing curly braces in the end.

The first [m]System.out.println("Enter text: ");[/m] should in fact be [m]print[/m] instead of [m]println[/m] because the example in the assignment does not have a new line:

Enter text: IDK how that happened. TTYL.
 

1. What is a text message expander program?

A text message expander program is a software application that automatically replaces abbreviations and shortcuts with their corresponding full words or phrases to save time and effort when typing messages on a phone or computer.

2. How does the 3.15 Program's text message expander work?

The 3.15 Program's text message expander works by storing a list of commonly used abbreviations and their corresponding full words or phrases. When a user types one of these abbreviations, the program automatically replaces it with the full word or phrase, making the message quicker to type and easier to understand.

3. Can I customize the abbreviations and expansions in the 3.15 Program's text message expander?

Yes, the 3.15 Program's text message expander allows users to customize the list of abbreviations and expansions according to their personal preferences. Users can add, edit, or delete abbreviations and their corresponding full words or phrases as needed.

4. Is the 3.15 Program's text message expander available for all devices?

The 3.15 Program's text message expander is a Java program, which means it can be run on any device that has Java installed. This includes computers, smartphones, and tablets, as long as they have a Java Virtual Machine installed.

5. Are there any potential drawbacks to using a text message expander program like 3.15?

One potential drawback of using a text message expander program is that it may lead to miscommunication if the person receiving the message is not familiar with the abbreviations and expansions being used. Additionally, the program may not always recognize the context of a message and may replace an abbreviation with the wrong word or phrase. It is important for users to double-check their messages before sending them to ensure accuracy and clarity.

Similar threads

  • Programming and Computer Science
Replies
3
Views
5K
  • Programming and Computer Science
Replies
1
Views
6K
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top