Question

Text message abbreviation decoder (Java) (1) Complete the following method: /** * Decodes the text abbreviation....

Text message abbreviation decoder (Java)

(1) Complete the following method:

/**
 * Decodes the text abbreviation.
 *
 * @param textAbbr Text abbreviation.
 * @return The decoded abbreviation if known. Otherwise, returns Unknown.
 */
public static String decTextAbbr(String textAbbr) {
    // FILL IN BODY
}

If the parameter matches a known text message abbreviation, return the unabbreviated form, else return: Unknown. Support two abbreviations:

LOL -- laughing out loud, and

IDK -- I don't know.

For example:

decTextAbbr("LOL")

returns

laughing out loud

(2) Write a testing method to verify this method works for all expected inputs:

/**
 * Runs tests on the decTextAbbr method.
 */
public static void testDecTextAbbr() {
       System.out.println( "decTextAbbr(\"LOL\") expected 'laughing out loud', actual '" 
                + decTextAbbr("LOL") + "'");
       System.out.println( /* FIX ME */);
       System.out.println( /* FIX ME */);
}

Run this test method from the main method to verify the decTextAbbr method is working correctly.


(3) Expand the method to also decode these abbreviations.

  • IMHO -- in my humble opinion
  • TMI -- too much information
  • BFF -- best friends forever
  • ROFL -- rolling on floor laughing
  • LMK -- let me know

extend the testDecTextAbbr() method to also verify these cases work correctly. When complete, your testDecTextAbbr() method should have at least 6 tests.

TextMsgExpander.java

public class TextMsgExpander {

/* Add your methods here */

public static void main(String[] args) {
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class TextMsgExpander {

    /**
     * Decodes the text abbreviation.
     *
     * @param textAbbr Text abbreviation.
     * @return The decoded abbreviation if known. Otherwise, returns Unknown.
     */
    public static String decTextAbbr(String textAbbr) {
        if (textAbbr.equals("LOL")) {
            return "laughing out loud";
        } else if (textAbbr.equals("IDK")) {
            return "I don't know";
        } else if (textAbbr.equals("IMHO")) {
            return "in my humble opinion";
        } else if (textAbbr.equals("TMI")) {
            return "too much information";
        } else if (textAbbr.equals("BFF")) {
            return "best friends forever";
        } else if (textAbbr.equals("ROFL")) {
            return "rolling on floor laughing";
        } else if (textAbbr.equals("LMK")) {
            return "let me know";
        }
        return textAbbr;
    }

    /**
     * Runs tests on the decTextAbbr method.
     */
    public static void testDecTextAbbr() {
        System.out.println("decTextAbbr(\"LOL\") expected 'laughing out loud', actual '" + decTextAbbr("LOL") + "'");
        System.out.println("decTextAbbr(\"IDK\") expected 'I don't know', actual '" + decTextAbbr("IDK") + "'");
        System.out.println("decTextAbbr(\"IMHO\") expected 'in my humble opinion', actual '" + decTextAbbr("IMHO") + "'");
        System.out.println("decTextAbbr(\"TMI\") expected 'too much information', actual '" + decTextAbbr("TMI") + "'");
        System.out.println("decTextAbbr(\"BFF\") expected 'best friends forever', actual '" + decTextAbbr("BFF") + "'");
        System.out.println("decTextAbbr(\"ROFL\") expected 'rolling on floor laughing', actual '" + decTextAbbr("ROFL") + "'");
        System.out.println("decTextAbbr(\"LMK\") expected 'let me know', actual '" + decTextAbbr("LMK") + "'");
    }

    public static void main(String[] args) {
        System.out.println("decTextAbbr(\"LOL\") expected 'laughing out loud', actual '" + decTextAbbr("LOL") + "'");
        System.out.println("decTextAbbr(\"IDK\") expected 'I don't know', actual '" + decTextAbbr("IDK") + "'");
        System.out.println("decTextAbbr(\"IMHO\") expected 'in my humble opinion', actual '" + decTextAbbr("IMHO") + "'");
        System.out.println("decTextAbbr(\"TMI\") expected 'too much information', actual '" + decTextAbbr("TMI") + "'");
        System.out.println("decTextAbbr(\"BFF\") expected 'best friends forever', actual '" + decTextAbbr("BFF") + "'");
        System.out.println("decTextAbbr(\"ROFL\") expected 'rolling on floor laughing', actual '" + decTextAbbr("ROFL") + "'");
        System.out.println("decTextAbbr(\"LMK\") expected 'let me know', actual '" + decTextAbbr("LMK") + "'");
    }

}
Add a comment
Know the answer?
Add Answer to:
Text message abbreviation decoder (Java) (1) Complete the following method: /** * Decodes the text abbreviation....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • matlab 3. Write a function called MessageDecode that matches an input string scalar to a known...

    matlab 3. Write a function called MessageDecode that matches an input string scalar to a known text message abbreviation, and output the unabbreviated form if known. Otherwise, output “Unknown message”. Support the abbreviations: BFF—best friends forever • BTW-by the way • IDK—I don't know • IMHO—in my humble opinion • LOL—laughing out loud • TMI—too much information Restriction: use switch statement. For example, >> myString="BFF"; >> MessageDecode (myString) ans- "best friends forever" (Hint: part of the code may like: switch...

  • Is there any way that I can call method in other class without constructor in java?...

    Is there any way that I can call method in other class without constructor in java? public class Chest { private String contents; public String getContents()    {        return contents;    } public void setContents(String contents)    {               this.contents = contents;           } I need to set content and print out in the main method, but it keep gives me a error message when I try Chest.setContents("Gold"); on main class. I suppose...

  • JAVA Write a method that accepts a String as an argument. The method should use recursion...

    JAVA Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String. Then, modify the method you just wrote so it displays the String backwards. The following code does not correctly display the String backwards. It merely moves the first character of the String to the end: public static void displayCharacter(String s)    {        if(s.length() == 0)            return;        else       ...

  • Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called...

    Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called HW4P1 and add the following: • The main method. Leave the main method empty for now. • Create a method named xyzPeriod that takes a String as a parameter and returns a boolean. • Return true if the String parameter contains the sequential characters xyz, and false otherwise. However, a period is never allowed to immediately precede (i.e. come before) the sequential characters xyz....

  • java 1. Write a method header on line three with the following specs: Returns: a boolean...

    java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main {       {        return true;    } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main {       {    String ans = name.toUpperCase();...

  • Let's fix the displayMenu() method! First, edit the method to do the following: We want to...

    Let's fix the displayMenu() method! First, edit the method to do the following: We want to also allow the user to quit. Include a "Quit" option in the print statements! Have it get the user input from within the method itself and return an int based on the user's choice. (Make sure to also edit the method header and how it is called back in the main() method!) What is the method's return type now?                  ...

  • Check if an array is a heap in Java. Complete the method isHeapTree Together, these methods...

    Check if an array is a heap in Java. Complete the method isHeapTree Together, these methods are meant to determine if an array of objects corresponds to a heap. The methods are generic, and they should work with an array of any type T that implement Comparable<T>. Implement the second method so that it uses recursion to process the complete tree/subtree whose root is at position i in the array arr. The method should return true if that tree/subtree is...

  • I was presented with this problem: Create a Java class MonthNames with a single static method...

    I was presented with this problem: Create a Java class MonthNames with a single static method getMonthName which Takes a single integer corresponding to a month of the year, 1 representing January through 12 representing December, and Returns a string for the name of the month. This is what I have so far public class MonthNames {    public static String getMonthName (int numMonth) {        return "month"; }        public static void main (String [] args) {...

  • Hi so I am currently working on a project for a java class and I am...

    Hi so I am currently working on a project for a java class and I am having trouble with a unit testing portion of the lab. This portion wants us to add three additional tests for three valid arguments and one test for an invalid argument. I tried coding it by myself but I am not well versed in unit testing so I am not sure if it is correct or if the invalid unit test will provide the desired...

  • Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13...

    Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13 Assignment 13 Preparation This assignment will focus on the use of object methods during event handling. Assignment 13 Assignment 13 Submission Follow the directions below to submit Assignment 13: This assignment will be a modification of the Assignment 12 program (see EncryptionApplication11.java below). Replace the use of String concatenation operations in the methods with StringBuilder or StringBuffer objects and their methods. EncryptTextMethods.java ====================== package...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT