Problem Statement
A store has been notified by a manufacturer that a certain product it carries has been deemed unsafe. The store must now send out recall notices to all customers who purchased that product. Customer information will be given as a String[], customers, where each element represents a single customer and is formatted as (quotes and brackets for clarity only): "<CUSTOMER_ID> <CUSTOMER_NAME>", where <CUSTOMER_ID> is an integer which uniquely identifies a customer, and <CUSTOMER_NAME> is the name of the customer. Transaction records will be given as a String[], transactions, where each element represents a single purchase and is formatted as (quotes and brackets for clarity only): "<CUSTOMER_ID> <PRODUCT_ID>", where <CUSTOMER_ID> is an integer which corresponds directly to the <CUSTOMER_ID>s in customers and <PRODUCT_ID> is an integer which identifies a unique product. Given an int, productId, return the names of all the customers who have purchased the recalled product identified by productId. The customer names should be returned as a String[] sorted in alphabetical order. If no customers meet the criteria, return an empty String[].
Definition
- Class:
- ProductRecall
- Method:
- customersNotified
- Parameters:
- String[], String[], int
- Returns:
- String[]
- Method signature:
- String[] customersNotified(String[] transactions, String[] customers, int productId)
- (be sure your method is public)
Constraints
- transactions and customers will each contain between 1 and 50 elements, inclusive.
- Each element of transactions will be formatted as "<CUSTOMER_ID> <PRODUCT_ID>" where: - <CUSTOMER_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_ID> exists in customers - <PRODUCT_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_ID> and <PRODUCT_ID> are separated by a single space.
- transactions contains no duplicate elements.
- Each element of customers will contain between 3 and 50 characters, inclusive.
- Each element of customers will be formatted as "<CUSTOMER_ID> <CUSTOMER_NAME>" where: - <CUSTOMER_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_NAME> contains only lowercase letters ('a'-'z') and is at least one letter long. - <CUSTOMER_ID> and <CUSTOMER_NAME> are separated by a single space.
- There are no duplicate <CUSTOMER_ID>s or <CUSTOMER_NAME>s in customers.
- productId is between 0 and 100, inclusive.
Examples
{"0 40", "1 20", "2 40"}{"0 klein", "1 gallagher", "2 white"}40
Returns: { "klein", "white" }Customers with ids of 0 and 2 bought the product with id 40. The customer with id 0 is "klein" and the customer with id 2 is "white". The returned String[] contains these two names in alphabetical order.{"100 55", "100 20", "100 75", "50 20"}{"0 fernandez", "50 west", "100 weston"}20
Returns: { "west", "weston" }Both customers in transactions bought the product with id 20. "west" comes before "weston" alphabetically.{"0 10", "1 11", "30 30", "2 2"}{"0 hedberg", "1 elliot", "2 adams", "30 spitz"}100
Returns: { }None of the customers bought the product with id 100, so an empty String[] is returned.