Computer Science 15-100 (Lecture 18), Spring 2009
Homework 5
Due: Thu 19-Feb-2009 at 11:59pm (email copy) and at Friday's
class/recitation
(identical physical copy)
(no late submissions accepted).
Read this first:
Read the instructions from hw4 first (changing "hw5" for "hw4" where appropriate).
Country | Gold | Silver | Bronze | Total |
China | 51 | 21 | 28 | 100 |
USA | 36 | 38 | 36 | 110 |
Russian Fed. | 23 | 21 | 28 | 72 |
Great Britain | 19 | 13 | 15 | 47 |
... | ... | ... | ... | ... |
The question we will be addressing is: which country won overall?
This depends on how you weight the gold, silver, and bronze medals.
For example, if you only count gold medals (give them a weight of 1 each,
with silvers and bronzes weighted 0 each), then China clearly won. But
if you weight each medal equally (all with a weight of 1, say), then the
United States (USA in the chart) won. There are other weightings, too,
of course. For example, if you think gold medals and silver medals are
each worth 1, but bronze medals are worth -3 (peculiar, yes, but also quite
legal), then there turns out to be a 3-way tie between the Czech Republic,
Poland, and Spain (all with 6 total points by those weights).
Based on this description, write a method, beijingOlympicsWinner, that takes 3 (possibly-negative,
possibly-zero) integers, the weightings for gold, silver, and bronze medals
(in that order), and a fourth parameter -- a String containing the path to
the data file -- and returns a string containing the name of the overall
winning country (exactly as the name appears in the first column). If
there is a tie, then return all the winning country names in a single
string, separated by vertical bars ("|"), ordered in the same order they
appear in the file. So, with the weightings of 1, 1, and -3 from
above, you would return "Spain|Poland|Czech Republic" (as they appear in
that order when listed by total medals, which is how the file is arranged).
Note: when we test your method, we will use a different data file --
same format, but different data.
Hint: you might want to tell the scanner to use a comma as a
delimiter!
Pittsburgh, PA
Current Local Conditions at:
Pittsburgh International Airport
Lat: 40.51 N Lon: 80.22 W Elev: 1150 ft
Last Update: 02/14/09, 05:51 PM EST
Weather: Mostly Cloudy
Temperature: 32°F (0°C)
Humidity: 79 %
Wind Speed: NW 10 MPH
Barometer: 29.97 in. (1016.8 mb)
Dewpoint: 26°F (-3°C)
Wind Chill: 24°F (-4°C)
Visibility: 10.00 mi.
Based on this description, write a method, miamiHeat, that takes no
parameters and returns a single integer -- how many degrees Fahrenheit
warmer it is at this time in Miami, FL, as compared to Pittsburgh, PA.
For example, at the same time the data above was read, the temperature in
Miami, FL, was 75 degrees Fahrenheit (sigh...), so the difference is 75-32,
or 43 degrees. So the method would return 43. Of course, this
value changes constantly, and your method must return the current
difference, whatever it is. Also, if Pittsburgh is warmer than Miami
(not likely in the next few months), then the method would return a negative
value.
Note: as should be apparent, to complete this problem you will
have to follow the steps given above to find the URL for Miami's current
weather conditions.
Further note: it is very hard to write a good test method for
real-time varying data. Anything remotely reasonable will be accepted.
Carpe diem!