Problem Statement
Each rating must be a decimal number between 0.0 and 10.0 inclusive, having exactly one digit to the right of its decimal point. Furthermore, the digit to the right of the decimal point must be a 0 or a 5. The degree of difficulty must be between 1.0 and 4.0 inclusive and have exactly one digit (possibly 0) to the right of its decimal point. Exactly 3 characters are used to express the degree of difficulty and each rating, with the exception that a rating of 10.0 uses 4 characters.
We know the score that our diver needs on her final dive to win a medal. We know the degree of difficulty of her final dive. But when the ratings appear on the scoreboard, one of the ratings appears as "?.?" due to an electronic malfunction. What is the smallest legal rating from that judge that will result in a medal?
Create a class Diving that contains a method needed that is given a
The method returns the smallest legal rating that would result in a medal for our diver, expressed as a
Definition
- Class:
- Diving
- Method:
- needed
- Parameters:
- String, String, String
- Returns:
- String
- Method signature:
- String needed(String difficulty, String need, String ratings)
- (be sure your method is public)
Constraints
- difficulty will be a legally expressed degree of difficulty.
- need will be a value between 0 and 120 inclusive and will contain a decimal point followed by exactly two digits.
- need will contain no more than 6 characters (but may have leading zeroes).
- ratings will consist of 4 legally expressed ratings and "?.?", separated by 4 single spaces (' ').
Examples
"3.2"
"50.32"
"5.5 7.5 10.0 ?.? 4.5"
Returns: "0.0"
Even if the unknown rating is thrown out as the low rating, the resulting score is 3.2*(5.5+7.5+4.5) which exceeds the needed score of 50.32.
"3.2"
"50.32"
"5.5 5.5 10.0 ?.? 4.5"
Returns: "5.0"
If the unknown rating is no help, then our score would be 3.2*(5.5 + 5.5 + 4.5) = 49.60 which is too low. If the unknown rating is 5.0, then it will replace the 4.5 yielding a score of 3.2*(5.5+5.5+5.0) = 51.2 which is enough for a medal.
"4.0"
"120.00"
"9.5 10.0 ?.? 10.0 10.0"
Returns: "10.0"
We need to be able to count 3 ratings of 10.0 to achieve 120.00. One of the existing 10.0's will be thrown out as the high rating, so we need a perfect 10.0 to get a medal.
"4.0"
"120.00"
"9.5 10.0 ?.? 9.5 10.0"
Returns: "-1.0"
Even a 10.0 will leave us short of the needed score of 120.
"2.0"
"59.00"
"9.5 10.0 ?.? 9.5 10.0"
Returns: "10.0"
"2.0"
"9.09"
"0.5 10.0 ?.? 0.5 0.5"
Returns: "4.0"
"2.0"
"59.01"
"?.? 10.0 9.5 9.5 10.0"
Returns: "-1.0"
"2.0"
"0.00"
"6.0 9.5 9.5 0.0 ?.?"
Returns: "0.0"
"2.0"
"0.00"
"0.0 0.0 ?.? 0.0 0.0"
Returns: "0.0"
"2.3"
".01"
"0.0 0.0 ?.? 0.0 0.5"
Returns: "0.5"
"1.1"
"16.51"
"?.? 5.0 5.5 4.5 6.0"
Returns: "5.0"
"1.1"
"16.50"
"?.? 5.0 5.5 4.5 6.0"
Returns: "0.0"
"2.0"
"24.01"
"?.? 1.0 5.5 5.5 10.0"
Returns: "1.5"
"2.1"
"24.01"
"?.? 1.0 5.5 5.5 10.0"
Returns: "0.0"
"2.0"
"23.99"
"?.? 1.0 5.5 5.5 8.0"
Returns: "0.0"
"2.0"
"24.02"
"?.? 1.0 5.5 5.5 8.0"
Returns: "1.5"
"2.0"
"38.01"
"?.? 1.0 5.5 5.5 8.0"
Returns: "-1.0"
"2.0"
"38.00"
"?.? 1.0 5.5 5.5 8.0"
Returns: "8.0"
"3.3"
"47.85"
"0.5 5.5 3.5 7.0 ?.?"
Returns: "5.5"
"2.2"
"23.10"
"0.0 5.0 5.0 10.0 ?.?"
Returns: "0.5"
"1.0"
"3.00"
"1.0 1.0 1.0 1.0 ?.?"
Returns: "0.0"
"3.7"
"38.86"
"?.? 2.5 3.5 4.5 5.5"
Returns: "3.0"
"1.0"
"15.01"
"?.? 5.0 5.0 5.0 5.0"
Returns: "-1.0"
"3.3"
"47.85"
"0.5 5.5 3.5 7.0 ?.?"
Returns: "5.5"
"1.0"
"4.00"
"1.0 ?.? 1.0 1.0 1.0"
Returns: "-1.0"
"1.0"
"15.00"
"1.0 2.0 3.0 4.0 ?.?"
Returns: "-1.0"
"1.0"
"15.10"
"5.0 5.0 5.0 ?.? 5.0"
Returns: "-1.0"
"1.0"
"7.00"
"2.0 2.0 2.0 2.0 ?.?"
Returns: "-1.0"
"1.0"
"22.50"
"9.0 6.5 6.5 2.0 ?.?"
Returns: "-1.0"
"4.0"
"12.75"
"0.0 1.0 1.0 ?.? 10.0"
Returns: "1.5"
"1.0"
"16.00"
"5.0 5.0 5.0 5.0 ?.?"
Returns: "-1.0"
"1.0"
"1.06"
"0.0 0.0 0.0 ?.? 10.0"
Returns: "1.5"