In this assignment, you’ll decode Twitter messages that include Internet abbrevi
ID: 3781550 • Letter: I
Question
In this assignment, you’ll decode Twitter messages that include Internet abbreviations, such as LOL and IRL. The starter program decodes two abbreviations.
step 3: --Convert the user's tweet to a decoded tweet, replacing the abbreviations directly within the tweet. You only need to replace the first instance of a particular abbreviation.
Here is an example program execution for step 3:
Entertweet:I'mgoingtohangoutwithmyBFFIRLtomorrow.
Decodedtweet:I'mgoingtohangoutwithmybestfriendsforeverinreallife tomorrow.
Another example execution for step 3 (user input is highlighted here for clarity):
Entertweet:So, IMHO he was going FTW, but I was so LOL that my BFF thought I was going to start crying IRL! Anyway, gotta go, TTYL... I'm going AFK.
Decodedtweet:So,in my humble opinion he was going forthe win, but Iwas so laughing out loud that my bestfriends forever thought I was going to start crying in real life! Anyway, gotta go, talk to you later... I'm going away from keyboard.
Explanation / Answer
Please find the below solution:
package org.learning.chegg.problem;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TweetDecoder {
private static Map<String, String> map;
private static List<String> listOfAbbreviations;
public static void main(String[] args) throws IOException {
initialize();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
while(true){
System.out.println("Enter Tweet: ");
String tweet = bufferedReader.readLine();
if(tweet.equals("exit")){
break;
}
for(String abbr: listOfAbbreviations){
if(tweet.contains(abbr)){
tweet = tweet.replaceAll(abbr, map.get(abbr));
}
}
System.out.println("Decoded Tweet: "+tweet);
}
bufferedReader.close();
}
public static void initialize(){
map = new HashMap<>();
listOfAbbreviations = new ArrayList<String>();
listOfAbbreviations.add("BFFIRL");
map.put("BFFIRL", "bestfriendsforeverinreallife");
listOfAbbreviations.add("IMHO");
map.put("IMHO", "in my humble opinion");
listOfAbbreviations.add("FTW");
map.put("FTW", "for the win");
listOfAbbreviations.add("LOL");
map.put("LOL", "laughing out loud");
listOfAbbreviations.add("BFF");
map.put("BFF", "bestfriends forever");
listOfAbbreviations.add("IRL");
map.put("IRL", "in real life");
listOfAbbreviations.add("TTYL");
map.put("TTYL", "talk to you later");
listOfAbbreviations.add("AFK");
map.put("AFK", "away from keyboard");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.