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

I can\'t find the reason why the inputs \"ILR\", \"LRI\", \"LIR\", \"RLI\" & \"R

ID: 3848016 • Letter: I

Question

I can't find the reason why the inputs "ILR", "LRI", "LIR", "RLI" & "RIL" are outputting "Did you mean LOL? LOL = laughing out loud".

---The inputs above need to output "Did you mean IRL? IRL = in real life " but they do not.

Question: For abbreviations that do not match the supported abbreviations, check for common misspellings. Provide a suggestion for correct abbreviation along with the decoded meaning.

Example:

If the user enters "LLO", your program will print...
Did you mean LOL? LOL = laughing out loud
(end with a new line)

Original Code

import java.util.Scanner;

public class TweetDecoder {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

String origTweet = "";

System.out.println("Enter abbreviation from tweet: ");

origTweet = scnr.next();

System.out.println("You entered " + origTweet);

/* FIXME: Add all the possible misspellings for each of the supported abbreviations.

Note the number of combinations for each 3-letter abbreviation? */

if (origTweet.equals("LOL")) {

System.out.println("LOL = laughing out loud");

}

else if (origTweet.equals("BFN")) {

System.out.println("BFN = bye for now");

}

else if (origTweet.equals("FTW")) {

System.out.println("FTW = for the win");

}

else if (origTweet.equals("IRL")) {

System.out.println("IRL = in real life");

}

else {

System.out.println("Sorry, don't know that one.");

}

return;

}

}

After My Editing

import java.util.Scanner;

public class TweetDecoder {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

String origTweet = "";

System.out.println("Enter abbreviation from tweet: ");

origTweet = scnr.next();

System.out.println("You entered " + origTweet);

if (origTweet.equals("LOL")) {

System.out.println("LOL = laughing out loud");

}

else if (origTweet.equals("BFN")) {

System.out.println("BFN = bye for now");

}

else if (origTweet.equals("FTW")) {

System.out.println("FTW = for the win");

}

else if (origTweet.equals("IRL")) {

System.out.println("IRL = in real life");

}

else {

char x = origTweet.charAt(0);

char y = origTweet.charAt(1);

char z = origTweet.charAt(2);

int lol = 'L'+'O'+'L';

int bfn = 'B'+'F'+'N';

int ftw = 'F'+'T'+'W';

int irl = 'I'+'R'+'L';

int sum = x + y + z;

if (sum == lol)

System.out.println("Did you mean LOL? LOL = laughing out loud");

else if (sum == bfn)

System.out.println("Did you mean BFN? BFN = bye for now");

else if (sum == ftw)

System.out.println("Did you mean FTW? FTW = for the win");

else if (sum == irl)

System.out.println("Did you mean IRL? IRL = in real life");

else

System.out.println("Sorry, don't know that one.");

}

return;

}

}

Explanation / Answer

int bfn = 'B'+'F'+'N';

int irl = 'I'+'R'+'L';

for both sum = 231.

This is because you are adding the ascii values of characters L,O,I,R.

Now for LOL , sum of ascii values = 76 + 79 + 76 = 231

and for IRL,it is = 73+ 82+76 = 231

so the sums are equal, that is why it is going to the first matching condition

if (sum == lol)
System.out.println("Did you mean LOL? LOL = laughing out loud");

import java.util.Scanner;

class TweetDecoder
{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String origTweet = "";
System.out.println("Enter abbreviation from tweet: ");
origTweet = scnr.next();
System.out.println("You entered " + origTweet);
if (origTweet.equals("LOL")) {
System.out.println("LOL = laughing out loud");
}
else if (origTweet.equals("BFN")) {
System.out.println("BFN = bye for now");
}
else if (origTweet.equals("FTW")) {
System.out.println("FTW = for the win");
}
else if (origTweet.equals("IRL")) {
System.out.println("IRL = in real life");
}
else {
char x = origTweet.charAt(0);
char y = origTweet.charAt(1);
char z = origTweet.charAt(2);


System.out.println();
if ((x == 'O'|| x == 'L') &&( y == 'L'|| y == 'O') && (z == 'L' || z == 'O'))
System.out.println("Did you mean LOL? LOL = laughing out loud");
else if ((x == 'B'|| x== 'F' || x == 'N') && (y == 'F' || y == 'B' || y == 'N' )&& (z == 'N'|| z == 'B' || z == 'F'))
System.out.println("Did you mean BFN? BFN = bye for now");
else if ((x == 'F' || x == 'T' || x == 'W') && (y == 'T'|| y == 'F' || y == 'W') && (z == 'W' || z == 'F' || z == 'T'))
System.out.println("Did you mean FTW? FTW = for the win");
else if ((x == 'I' || x == 'R' || x == 'L') && (y == 'I' || y == 'R' || y == 'L') && (z == 'L'|| z == 'I' || z == 'R'))
System.out.println("Did you mean IRL? IRL = in real life");
else
System.out.println("Sorry, don't know that one.");
}
return;
}
}

Output:

Enter abbreviation from tweet: LIR
You entered LIR

Did you mean IRL? IRL = in real life

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