-3

I am not sure what I am doing wrong. Any help would be great!


This is the output I am looking for:

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.

This is the output I'm getting

debug:
Enter text: IDK how that happened. TTYL.
You entered: IDK how that happened. TTYL.
BUILD SUCCESSFUL (total time: 30 seconds)
package textmsgexpander;

import java.util.Scanner;

/**
 *
 */
public class TextMsgExpander {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        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";
        String userMSG = "";

        //User enters the text and gets output
        System.out.println("Enter text: ");
        userMSG = scnr.nextLine();

        //Program outputs what user entered above
        System.out.println("You entered: " + userMSG);

        if (userMSG.contains(BFF)){
            userMSG = userMSG.replace("BFF", BFF);
            System.out.println("Replaced 'BFF' with " + BFF);
        {
        else if (userMSG.contains(IDK)) {
            userMSG = userMSG.replace("IDK", IDK);
            System.out.println("Replaced 'IDK' with " + IDK);       
        }
        else if (userMSG.contains(JK)); {
            userMSG = userMSG.replace("JK", JK);
            System.out.println("Replaced 'JK' with " + JK);       
        }
        else if (userMSG.contains(TMI)); {
            userMSG = userMSG.replace("TMI", TMI);
            System.out.println("Replaced 'TMI' with " + TMI);       
        }
        else if (userMSG.contains(TTYL)); {
            userMSG = userMSG.replace("TTYL", TTYL);
            System.out.println("Replaced 'TTYL' with " + TTYL);
        else {
            System.out.println("Unknown");
        }

        //Program outputs message with expanded abbreviations
        System.out.println("Expanded: " + userMSG);
    }
}
fabian
  • 80,457
  • 12
  • 86
  • 114

1 Answers1

1

userMSG.contains(BFF) should be userMSG.contains("BFF"). You need to apply the same change to your other conditions.

Note that using a map would probably be easier (as in less code).

assylias
  • 321,522
  • 82
  • 660
  • 783