X
COMP 1020
Exercise 3
Now that we have the data in an array, we can calculate the statistics. Add the possibility of an optional fourth token on a line, found only in readings with precipitation, containing the duration of precipitation. This will be given in the format 1:43 where 1 is the number of hours and 43 is the number of minutes (may be one or two digits). The : may be omitted, meaning the value is just the number of hours (zero minutes), or the number of hours may be omitted. For example:
-10,3NW,15cm,4:38 5,15SW,8mm,2:8 8,8ENE,2mm,:25 -5,0,7cm,1 -3,0,3mm
Download the complete Weather Station program and add the following features to it:
- Add hours and minutes instance variables to the Reading class. Zero values for both indicate no data (or no precipitation).
- Add the code to the main program to parse the extra data on the line. Hint: once you have split the CSV line into tokens, you may want to take the fourth token (if it exists) and split it according to the position of the :.
- Make sure you deal with the same situations as the original program: neither duration values can be negative, and use trim() to remove excess whitespace.
Submit your complete modified program by the due date specified in the course schedule. Add a comment to the top of the program indicating whether you think it works in all cases described above, or if there are some it has trouble processing (and why).