CSC212 Homework 3 2014
--D. Thiebaut (talk) 16:21, 24 September 2014 (EDT)
This homework is due on Oct. 2nd, 2014, at 11:55 p.m.
Contents
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
- read the temperature file,
- record the year when the rain was maximum,
- record the year when the sun was maximum,
- 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 below:
Cardiff Bute Park
Location 3176E 1773N, 9 metres amsl
Estimated data is marked with a * after the value.
yyyy mm tmax tmin af rain sun
degC degC days mm hours
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
...
2009 7 20.2 13.1 0 194.1 ---
2009 8 20.7 --- 0 76.0 120.5
2009 9 19.1 10.6 0 34.7 ---
2009 10 16.3 8.6 0 73.6 ---
2009 11 12.6 6.5 0 220.4 ---
2009 12 7.2 0.0 15 114.9 ---
2010 1 6.0 -1.2 16 73.5 ---
2010 2 7.3 0.8 7 72.1 ---
- 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
- The output format should be the same as for Problem 1.
- 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.
Problem #3
- Convert the Python-List program of [[ | this page]].