Problem Statement
A store has decided to reward its best customers by sending them discount coupons in the mail. First, it must use its records to identify its highest spending customers. 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 the total transactions for a single customer and is formatted as (quotes and brackets for clarity only): "<CUSTOMER_ID> <PURCHASE_AMOUNT>", where <CUSTOMER_ID> is an integer which corresponds directly to the <CUSTOMER_ID>s in customers, and
<PURCHASE_AMOUNT> is the total amount of money spent by that customer in dollars. Given an int, threshold, return the names of all the customers who have spent at least threshold dollars. 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:
- CustomerAppreciation
- Method:
- topSpenders
- Parameters:
- String[], String[], int
- Returns:
- String[]
- Method signature:
- String[] topSpenders(String[] transactions, String[] customers, int threshold)
- (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> <PURCHASE_AMOUNT>" where: - <CUSTOMER_ID> is an integer between 0 and 100, inclusive, with no extra leading zeros. - <CUSTOMER_ID> exists in customers - <PURCHASE_AMOUNT> is an integer between 1 and 99999, inclusive, with no extra leading zeros. - <CUSTOMER_ID> and <PURCHASE_AMOUNT> are separated by a single space.
- There are no duplicate <CUSTOMER_ID>s in transactions.
- 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.
- threshold is between 1000 and 50000, inclusive.
Examples
{"0 99", "1 2078", "3 2434", "2 1999"}{"2 walker", "4 vie", "1 smith", "3 jones", "0 vincent"}2000
Returns: { "jones", "smith" }The customers with ids 1 and 3 spent at least $2000. Customer id 1 belongs to "smith" and customer id 3 belongs to "jones". The return String[] contains those two names in sorted order.{"0 40000", "4 13400", "100 49999"}{"100 vasquez", "0 figg", "4 rhoads"}50000
Returns: { }Nobody spent $50000, so an empty String[] is returned.{"5 5000", "7 7000", "9 99999", "43 1000"}{"40 lopez", "43 griffin", "5 thomas", "6 greene", "7 rollins", "9 rollin"}1000
Returns: { "griffin", "rollin", "rollins", "thomas" }Everybody who made purchases spent at least $1000, so all the customers who appear in transactions will be returned. Notice that "rollin" comes before "rollins" alphabetically.