id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

tmhscs@gmail.com welcomeback > welcomeback_map_needToBuy
prev  |  next  |  chance

Given a String array of items and an integer array of quantities, create a TreeMap that uses Strings for keys and integers for values that contains all of the arrays contents, and then return a String using the following formatting.

"I need to buy QTY ITEM, QTY ITEM, ..., and QTY ITEM."
Where QTY is the quantity and ITEM is the item name.
If the QTY is more than 1, the ITEM should be plural.
The word "and" should only come before the last QTY ITEM.

welcomeback_map_needToBuy(["apple", "banana"], [3, 5]) → "I need to buy 3 apples, and 5 bananas."
welcomeback_map_needToBuy(["apple", "carrot", "banana"], [3, 1, 5]) → "I need to buy 3 apples, 5 bananas, and 1 carrot."
welcomeback_map_needToBuy(["banana"], [5]) → "I need to buy 5 bananas."

...Save, Compile, Run (ctrl-enter)

public String welcomeback_map_needToBuy(String[] items, int[] quantities) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy