Problem Statement
In an attempt to improve the quality of its inventory, a store would like to remove the products that have the lowest customer satisfaction rates. It will do this by checking its sales logs and determining which products have the highest return rates. Product information will be given as a String[], products, where each element represents a single product and is formatted as (quotes and brackets for clarity only): "<PRODUCT_ID> <PRODUCT_NAME>", where <PRODUCT_ID> is an integer which uniquely identifies a product, and <PRODUCT_NAME> is the name of the product. Sales records will be given as a String[], sales, where each element represents the sales summary of a single product and is formatted as (quotes and brackets for clarity only): "<PRODUCT_ID> <QTY_SOLD> <QTY_RETURNED>", where <PRODUCT_ID> is an integer which corresponds directly to the <PRODUCT_ID>s in products, <QTY_SOLD> is the total number of units sold, and <QTY_RETURNED> is the total number of units returned. Given an int, threshold, return the names of all the products that have a return rate of at least threshold percent. The product names should be returned as a String[] sorted in alphabetical order. If no products meet the criteria, return an empty String[].
Definition
- Class:
- CustomerSatisfaction
- Method:
- mostReturned
- Parameters:
- String[], String[], int
- Returns:
- String[]
- Method signature:
- String[] mostReturned(String[] sales, String[] products, int threshold)
- (be sure your method is public)
Constraints
- sales and products will each contain between 1 and 50 elements, inclusive.
- Each element of sales will be formatted as "<PRODUCT_ID> <QTY_SOLD> <QTY_RETURNED>" where: - <PRODUCT_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <PRODUCT_ID> exists in products - <QTY_SOLD> is an integer between 1 and 1000, inclusive, with no extra leading zeros. - <QTY_RETURNED> is an integer between 1 and <QTY_SOLD>, inclusive, with no extra leading zeros. - <PRODUCT_ID>, <QTY_SOLD>, and <QTY_RETURNED> are separated by single spaces.
- There are no duplicate <PRODUCT_ID>s in sales.
- Each element of products will contain between 3 and 50 characters, inclusive.
- Each element of products will be formatted as "<PRODUCT_ID> <PRODUCT_NAME>" where: - <PRODUCT_ID> is an integer between 0 and 50, inclusive, with no extra leading zeros. - <PRODUCT_NAME> contains only lowercase letters ('a'-'z') and is at least one letter long. - <PRODUCT_ID> and <PRODUCT_NAME> are separated by a single space.
- There are no duplicate <PRODUCT_ID>s or <PRODUCT_NAME>s in products.
- threshold is between 20 and 100, inclusive.
Examples
{"4 200 100","0 200 99","5 1000 1", "3 600 600"}{"5 toaster", "3 chair", "0 basket", "4 desk"}50
Returns: { "chair", "desk" }Products with ids of 4 and 3 have return rates of 50% or higher. The product represented by id 3 is a "chair" and has a return rate of 100% (600 sold, all 600 returned). The product represented by id 4 is a "desk" and has a return rate of 50% (200 sold, 100 returned).{"100 501 100", "50 5 1", "0 10 3"}{"50 napkin", "0 napkinholder", "100 towel"}20
Returns: { "napkin", "napkinholder" }"napkin" comes before "napkinholder" alphabetically.{"1 1000 1", "0 500 250", "2 1000 999"}{"0 dog", "1 cat", "2 goldfish"}100
Returns: { }No product has a return rate of 100%, so an empty String[] is returned.