Complete a function called
bestPlayer that accepts a single
String will contain multiple lines of comma-separated data, like this:
Tom Brady,3, 2 Cam Newton , 4, 5
The first value is the player's name. The second is the number of touchdowns that player scored, and the third is the number of field goals they scored. In American Football, each touchdown is worth 7 points and each field goal 3 points. (Technically, it's a bit more complicated than this, but we'll ignore missed point after attempts, two point conversions, and the fact that players don't usually score both touchdowns and field goals.)
bestPlayer should return a
String containing the name of the player in the passed data that
scored the most points.
In the example above, the correct result would be "Cam Newton".
If two players score the same number of points, you should return the one that appears first.
Note that zero is a valid number of points to have scored and should not be treated separately.
A few notes.
First, you'll want to use both
trim, two of our familiar functions for working with
Second, while each line will contain a record, there may be extra whitespace surrounding each record.
(The data was entered by a cat, who enjoys football but sometimes inserts whitespace for no discernible reason.)
Third, recall that you can use
Integer.parseInt to convert a
String to an
Finally, if the
String passed is
null or empty, you should return