Lab 4: Java Hash Maps

Due Date and Submission Requirements


The goal of this lab is:


WARNING: You may have issues with this lab if you are using an IDE that is not Eclipse.

This lab involces printing out Emojis. Some IDE have troubles displaying emojis. You may have to use a different IDE, or do some googling to get emojis to work for you.

Directions

In this lab, you will use Java’s HashMap library to build a program that will convert Emoji Codes (:GrinningFace:) to Emojis 😀. A user will be able to supply a sentence to your program with one-to-many Emoji Codes, and the program will display the same sentence, but with the Emojis substituted properly.

You will use Lab4Demo.java as a starting point, which can be found in the “Starting Code” section.

You will need to define the EmojiTranslator class, which must use a HashMap to hold mappings of emoji codes (Strings) to emojis (Strings). Then you must define the following methods:

1. public HashMap < String,String > loadHashTable(). This method reads in from a text file (emojis.txt), and fills the HashMap with the proper Key Value pairs. The keys of your HashMap will be the Emoji Codes (:GrinningFace:), and the value linked to the key will be the actual Emoji (😀). This method needs to return the filled HashMap. You can call this method from the constructor of the EmojiConverterClass.

2. public String convert(String sentence). This method takes in a sentence and will convert any word that is an emoji code to the actual emoji using the HashMap you built earlier. You can assume an emoji code will always be a word that begins and ends with a colon. This method needs to return the new sentence with the proper emojis. For example,
"Go Cats Go! :CatFaceWithWrySmile: Go Cats Go! :CatFaceWithWrySmile: :FlexedBiceps: :GrinningFace:"

Should be translate to

Go Cats Go! 😼 Go Cats Go! 😼 💪 😀

3. public String getEmoji(String code). This method takes in a String and will attempt to pull the Emoji who’s Emoji Code matches the argument. When getEmoji(“Taco”), is called, it will attempt to find the :Taco: emoji and then return the Taco Emoji (if it exists) 🌮. If the Emoji does not exist, then a “Emoji not found” error should be printed out (see sample output)

Rules

You are not allowed to use any data structure that is not a HashMap. The one exception is that you are allowed to use an Array when using the .split() method.

Starting Code

Hints

Required Output

When your program is run, your output should look exactlythe same as seen in this screenshot .

Grading (10 points)



Deductions
  • -10 points if you dont use a Hash Map