X1139: Add entries from array to a HashMap Instead of writing lots of lines of code,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Practical Management Science
ISBN: 978-1305250901
5th edition
Authors: Wayne L. Winston, Christian Albright
Posted Date:
Students also viewed these programming questions
-
Dennis Harding is considering acquiring a new automobile that he will use 100% for business. The purchase price of the automobile would be $48,500. If Dennis leased the car for five years, the lease...
-
In Figure 6.5, what rate of output (a) Maximizes total revenue? (b) Maximizes profit per unit? (c) Maximizes total profit? (Choose the higher level of output.) $18 Marginal cost 16 p = MC Profits...
-
In Exercises, find the six trigonometric function values of the specified angle. 3 at 6 3V3
-
On June 14, 1988, Thomas John Heck Jr. executed a note promising to pay Paul D. Heck \($51,000\) at 7 percent interest compounded annually. The note contains the following payment terms: Perpetual 90...
-
Baucom Manufacturing Corporation was started with the issuance of common stock for $50,000. It purchased $7,000 of raw materials and worked on three job orders during 2012 for which data follow....
-
A crystal was analyzed using X-ray diffraction with radiation from a copper source. The observed angle was 8.61. Determine the distance between layers of the crystal. d = Element (pm) CO 179 Cr 229...
-
Capstone Case: Sunrise Bakery Expansion The Sunrise Bakery Corporation was originally founded in Houston, TX in 1991 by Griffin Harris, who currently serves as the company's Chief Executive Officer....
-
Write an international business paper about the Irish economy
-
Consider rent control policies in the rental housing market and the negative aspects of this government intervention. Using what you have learned about DWL and welfare analysis; specifically discuss...
-
(a) Calculate QW and WQ. (b) Compute [Q, W]. (c) Compute trQ, trW, and tr[Q, W]. (d) Calculate det Q and det W. (e) Calculate the inverse Q-. Simplify the result so that no complex numbers are in the...
-
A dimerization reaction of 2 R molecules occurs on a catalyst surface to form a product P. The reaction proceeds through the following mechanism: (1) R(g) +* R* (2) 2R* P*+ * (3) P = P(g) + *...
-
On the last day of April, when the high temperature is 56 (Fahrenheit), you want to estimate the distribution of the high temperature on May 10. To do this, you estimate that the distribution of each...
-
In 2016 a group of three well-traveled individuals came together with an idea to start a business: Ari, an English teacher in the Sapa region of Vietnam; Luiz, a tour guide for a tourism outfit based...
-
iCoastal Corporation manufactures two types of kayaks-Ocean and fishing-and applies manufacturing overhead to all units using machine hours. Production information follows. Ocean Fishing Anticipated...
-
An interest bearing promissory note for 90 days at 5.6% p.a. has a face value of $120,000. If the note is discounted 20 days after the issue date at a rate of 6.8% p.a., calculate the amount of...
-
Allied Freight supplies goods to three customers, who each require 30 units. The company has two ware-houses. In warehouse 1, 40 units are available, and in warehouse 2, 30 units are available. The...
-
Suppose in the Dorian production model that no minimum production limits are placed on the individual vehicle types. However, minimum production limits are placed on all cars and on all minivans....
-
On average, 50 customers arrive per hour at a small post office. Inter-arrival times are exponentially distributed. Each window can serve an average of 25 customers per hour. Service times are...
-
Several years ago, Catherines Cattery Supplies signed a contract to deliver 5000 units of a special product each year to one of its customers at a price of $15 per unit. This contract, which runs for...
-
Cairns Farming is a small family run dairy farm, which is finding it hard to continue in business. After visiting a farm in Nienberg, Germany, it is considering buying equipment that will enable it...
-
The Anderson Group has identified the following capital expenditure proposals as acceptable. Only $150 000 is available for investment. Required: Determine the combination of proposals to be...
Study smarter with the SolutionInn App