Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

X1139: Add entries from array to a HashMap Instead of writing lots of lines of code, we could put all the words in an

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

X1139: Add entries from array to a HashMap Instead of writing lots of lines of code, we could put all the words in an array and then loop over the array adding them. You can assume that the size of the english array and the spanish one is equal. Your Answer: 1 void addWords (String[] english, String[] spanish) 2{ 4 5} 6 for (int i = 0; i < < >; i++) dictionary.put( < >, < >); Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. X285: Binary Tree Height Exercise The height of a binary tree is the length of the path to the deepest node. An empty tree has a height of 0, a tree with one node has a height of 1, and so on. Write a recursive function to find the height of the binary tree pointed at by root. Here are methods that you can use on the BinNode objects: interface BinNode { public int value(); public void setValue(int v); public BinNode left(); public BinNode right(); public boolean isLeaf(); Your Answer: public int BTheight (BinNode root) 4} Feedback 0.0/ 5.0 Your answer could not be processed because it contains errors: The solution is not recursive X1137: Get value from hashmap Consider a dictionary that given an English word, returns the Spanish word. Such a dictionary is stored in a HashMap () where the key is in English and the value is in Spanish. Write a method geteSpanish() that returns the Spanish word from the dictionary. If the word is not there you must return "?"; 1 HashMap dictionary = new HashMap (); 2 dictionary.put("blue", "azul"); 3 dictionary.put("green", "verde"); 4 dictionary.put("red", "rojo"); Your Answer: 1 String getSpanish (String english) 2 { 4 5 8} String spanish = dictionary.get( < >); if ( < >) return < >; else return < >; Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer. X1138: Add entries to HashMap Add new words to the dictionary. Write a method that adds the following words to the dictionary. Remember, you add words to a HashMap by calling the put() method. dictionary.put( < >, < >) Add the following words; the first word on the line is in English followed by the corresponding Spanish word. 1 "dog", "perro" 2 "cat", "gato" 3 "guinea pig", "cobaya" 4 "fish", "pez" 5 "bird", "pjaro" 6 "parakeet", "perico" 7 "turtle", "tortuga" 8 "snake", "serpiente" Your Answer: 1 void addNewWords () 2 { 4 5} // one Line per set of word added dictionary.put( < >, < >); Check my answer! Reset Next exercise Feedback Your feedback will appear here when you check your answer.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Management Science

Authors: Wayne L. Winston, Christian Albright

5th Edition

1305631540, 1305631544, 1305250907, 978-1305250901

More Books

Students also viewed these Programming questions