Answer:
Here is the JAVA program. I have added a few more abbreviations apart from LOL and IDK.
import java.util.Scanner; // to take input from user
public class MessageAbbreviation {
public static void main(String[] args) { //start of main() function body
Scanner input = new Scanner(System.in); // create object of Scanner
String abbreviation= ""; //stores the text message abbreviation
/* In the following lines the abbreviation string type variables contain the un-abbreviated forms */
String LOL = "laughing out loud";
String IDK = "i don't know";
String BFF = "best friends forever";
String IMHO = "in my humble opinion";
String TMI = "too much information";
String TYT = "take your time";
String IDC = "I don't care";
String FYI = "for your information";
String BTW = "by the way";
String OMG = "oh my God";
//prompts the user to enter an abbreviation for example LOL
System.out.println("Input an abbreviation:" + " ");
if(input.hasNext()) { // reads the abbreviation form the user
abbreviation= input.next(); }
// scans and reads the abbreviation from user in the abbreviation variable
/*switch statement checks the input abbreviation with the cases and prints the un abbreviated form in output accordingly. */
switch(abbreviation) {
case "LOL" : System.out.println(LOL);
break;
case "IDK" : System.out.println(IDK);
break;
case "BFF" : System.out.println(BFF);
break;
case "IMHO": System.out.println(IMHO);
break;
case "TMI": System.out.println(TMI);
break;
case "TYT": System.out.println(TYT);
break;
case "IDC": System.out.println(IDC);
break;
case "FYI": System.out.println(FYI);
break;
case "BTW": System.out.println(BTW);
break;
case "OMG": System.out.println(OMG);
break;
default : System.out.println("Unknown"); } } }
Explanation:
The program first prompts the user to enter an abbreviation. Lets say the user enters LOL. Now the switch statement has some cases which are the conditions that are checked against the input abbreviation. For example if the user enters LOL then the following statement is executed:
case "LOL" : System.out.println(LOL);
This means if the case is LOL then the message ( un abbreviated form) stored in the LOL variable is displayed on output screen So the output is laughing out loud.
Anything else entered other than the given abbreviations will display the message: Unknown
The output is attached as screen shot.