Problem Statement
John has recently held a "guess the number of peas in the jar" competition, and now he needs to find out who the winner is. He has recorded all the guesses each contestant has made, as well as their names. The contestant who is closest to the real answer wins. You may assume that their is a unique winner.
Create a class GuessPeas containing the method winner which takes as input a int[] guess and a String[] name and an int peas, the number of peas in the glass jar, and returns a String, the name of the contestant with the best guess. Element i in guess and name correspond to contestant i.
Definition
- Class:
- GuessPeas
- Method:
- winner
- Parameters:
- int[], String[], int
- Returns:
- String
- Method signature:
- String winner(int[] guess, String[] name, int peas)
- (be sure your method is public)
Constraints
- guess will contain between 1 and 50 elements.
- name will contain between 1 and 50 elements.
- guess will contain the same number of elements as name.
- Each element in guess will be between 1 and 10000.
- Each element in name will contain between 1 and 50 characters, inclusive.
- Each element in name will only contain upper and lower case letters ('A'-'Z','a'-'z').
- peas will be between 1 and 10000.
- There will be exactly one guess which is the best one.
Examples
{823,637,512,783,1073,600}{"Lars","Jimmy","Brett","Mike","Tom","Jack"}625
Returns: "Jimmy"
Below is a table of the people who guessed and how good their guess was (ie the difference between their guess and the correct answer). Name Difference ---- ---------- Lars 198 Jimmy 12 Brett 113 Mike 158 Tom 448 Jack 25 Clearly Jimmy made the best guess, and wins. The method should thus return "Jimmy".{5729,4509,8639,7203}{"Joe","Mary","John","Alice"}7203
Returns: "Alice"
Alice managed to guess exactly right, so of course she wins.{1,10000}{"MrUnderestimator","MrOverestimator"}5000
Returns: "MrUnderestimator"
Both guessers made horrible guesses, but one still has to win.{10}{"Alone"}20
Returns: "Alone"
With only one competitor, the winner is obvious.{6135,8110,4820,4527,5737,8740,8767,6963, 5585,4980,4971,6567,5103,9157,9193,6707, 7854,6040,7061,5875,9217,6287,6039,4807, 7759,9158,6675,5230,6070,5199,7836}{"tIRDqcUZyMwHxemLiikIKoUWflExrgaCXNy", "qeYrTJemCdcuZVNQX", "vnLCBIcsSrHXgyAyIgXgNiWk", "BKgrfnWaWOLOyjJgAfDRgmOrUsciwhSmxKMOxq", "gKWmgqcpcqQyuD", "FqwGcwFfWvlXMVUiREnIuuiTeQLoNabEbiIGrUSX", "mngVMLbdkrtSYvZNtKqaYELrfZhX", "WJTqGjjdDfORVDfqOpCZibOmHOc", "UACKKgvrrQvEKKCYpKZBxWhbjpxwKeAiHPnEucMZS", "TcwtrjXOKiPSbYXikNKnVdpggLahJchNdVVLGuNopEquQBD", "hOCYNcstBCcahosgzjwmGQHKABRXSJgWEXcybcuhGueBi", "zztGRxiStiRCVCsTqlivayrdCYYnqFLurYYV", "TUpGMEtYLKoOGtkFaMNR", "vBBIWIViMfRwSZNbhzaforR", "FwInIZggJLStzkwWvPhBTZdwRGOt", "vtbmqwSbYENmhIQqVzUtdZwICcsRzrxYZpnxw", "PrAR", "AYKHEEShxwEdsnliepD", "oCqBflbhcTheydTIaXlvAQxuZmuSEb", "ELGevIHwHTSNVHldXufqDXRMxXgKZFPSJwbxVcWtkxmwQgaHQY", "hJp", "KCjocFaHFIOIczJQX", "OIYsIZetzjGvGewkIdVIAgUsFdNbnhrCf", "NwHkxDrOTuzzquSNGEbYTPFtSsYqsTAe", "fbCKd", "PvUVffGFPqFpJtOOqkyUi", "eeeqUEShrNKHFWhovLtLBualgLqHH", "GJrlURMeazjMyuQDiuc", "RlTqf", "EOxbDItCfVpBetpVbEn", "pQCLSXiXJaSbNmvkCAHeVRrZqiWw"}8653
Returns: "FqwGcwFfWvlXMVUiREnIuuiTeQLoNabEbiIGrUSX"
Random case.