CSC212 Homework 3 2014

From dftwiki3
Revision as of 16:00, 24 September 2014 by Thiebaut (talk | contribs) (Problem #2)
Jump to: navigation, search

--D. Thiebaut (talk) 16:21, 24 September 2014 (EDT)


This homework is due on Oct. 2nd, 2014, at 11:55 p.m.


Problem #1

  • Create a text file in your directory with the following lines. Call it temperatures0.dat:


   1977   9   18.3     8.1       0    48.6   117.9
   1977  10   15.4     9.0       0    76.0    80.4
   1977  11   10.3     4.7       4   147.9    76.4
   1977  12    9.6     4.6       2    88.0    25.6
   1978   1    7.5     2.0       6   134.1    64.7
   1978   2    6.2     0.9      13   134.1    56.9
   1978   3   10.6     3.9       3   121.3   122.4
   1978   4   10.9     3.7       4    63.6   118.6
   1978   5   17.3     7.5       0    30.6   188.1
   1978   6   18.5     9.5       0    29.6   177.3
   1978   7   18.7    11.8       0   110.1   115.8
   1978   8   19.6    11.4       0    40.5   164.9
   1978   9   18.4    10.2       0    34.1   182.2
   1978  10   16.6     9.0       0    12.0    81.1


These numbers are weather numbers for Cardiff Bute Park, in the U.K. The 7 numbers on each line represent the following quantities, shown here with their standard abbreviation:

  • the year of the recording (yyyy)
  • the month of the recording (mm)
  • the max daily temperature in degrees Celcius (tmax)
  • the min daily temperature in degrees Celcius (tmin)
  • the number of days of frost (af)
  • the total rainfall (rain)
  • the sunshine duration (sun)


Your Assignment


  • Write a program called Hw3_1.java that will
  1. read the temperature file,
  2. record the year when the rain was maximum,
  3. record the year when the sun was maximum,
  4. output this information on two lines of text:
  javac Hw3_1.java  
  java Hw3_1 temperatures0.dat 
   rain 1977 147.90
   sun  1978 188.10


Submission


  • Submit your program to Moodle, Homework 3, Problem 1


Problem #2


  • Create a new version of your program and call it Hw3_2.java.
  • Create a new text file called temperatures.dat, with the contents found on this page.
  • You will notice that the new file will contain lines other than data lines (like the header), and that some data are missing, and replaced by "---". Your program has to be able to skip these non-data without problems. In particular, without generating exceptions to the operating system!
  • Using the program you wrote for Lab #5, build Hw3_2.java so that it will look for the max rain and sun recordings, and output 2 lines with the years and the max numbers found.


Requirements


  • You must declare and use your own exception class.
  • You must use a method to open the file,
  • You must use another method that reads only 1 line at a time from the input file and returns the year, rain and sun data found on that line. You can use an array or a triplet to pass these numbers back to the main program.


Submission


  • Submit your program to Moodle, Problem 2 Section.