Lab 4: Using arrays

The goal of this lab is to practice using arrays, including the args array.

1. Introduction

Your task in this lab is to write a program which receives as input a series of double values interpreted as the amount of rainfall in successive months. For example, if it were given twelve numbers

1.4 5.2 7.3 4.2 4.6 2.8 7.4 5.2 4.7 8.2 1.2 3.6

this would be interpreted as 1.4 units of rainfall in January, 5.2 in February, etc. You will be given several years' worth of data as one big long list of numbers. Your program will use this data to generate a table which gives for each month (1) the average rainfall for that month (over the years for which the data is given), (2) the rainfall for the most recent month, and (3) how much above or below average the most recent month is. The output will look something like

Jan     0.8210748805348682      0.6834390522400943      -0.13763582829477394
Feb     1.9194515641683012      1.5679950865951544      -0.3514564775731468
Mar     2.400285002785132       3.164213954524053       0.763928951738921
Apr     5.804738126602605       0.9830287758148275      -4.821709350787778
May     3.76182675153702        3.7344725369276395      -0.027354214609380367
Jun     3.403902173143365       2.9068214333763476      -0.4970807397670174
Jul     2.0318258917252052      1.9840330236370396      -0.04779286808816563
Aug     2.007361328245369       1.7773942658914221      -0.22996706235394693
Sep     3.7161954697495743      4.393987589988356       0.6777921202387818
Oct     5.0173608869616055      5.002715375175615       -0.014645511785990273
Nov     3.0615176722351523      3.063504430523706       0.0019867582885537693
Dec     2.447781305843466       2.7600102891290796      0.31222898328561355

2. Set up

Copy the following file from the course public directory:

cp /homeemp/tvandrun/pub/235/RainDataGen.class .

It is a program that generates random (within carefully defined ranges) of rainfall data for a random number (between 10 and 30) of years.

3. Your task

You are to write a program that does what is described above, which reads its data from the command line (from the args array). The following information should help you:

4. To turn in

  1. Start a script file.
  2. Display the source file.
  3. Compile
  4. Run the program
  5. Exit the script
  6. Print out the script file. Use the command a2ps instead of lpr-- this make the file print in "two-up" form, that is, two pages per page. (a2ps -P sp typescript-- or whatever the name of your script file is)

Make sure you have exited the script file before you print, or else it will print forever!

Then turn in the hard copy to me.


Thomas VanDrunen
Last modified: Tue Jan 23 13:03:06 CST 2007