CS 157 Spring 2003               Assignment 9 – Arrays and For Loops – along with some previous topics 

100 points

 

Assigned: 03/26/2003

Due: 04/02/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program.  This is another step up in complexity. Plan ahead!!

 

Main Assignment:

The National Weather Service wants a program to keep track of rainfall and report on rainfall amounts. The program should ask the user for how many days’ rainfall to keep track of (ensure that they give a number greater than 1 and less than or equal to 100), read in that many daily rainfall amounts (validating each amount to ensure it is between 0 and 10.0 inches (inclusive)), calculate and report the average (mean) daily rainfall, then report the daily amounts, with an indication next to all that are above the mean (see example below).

 

·        YOUR PROGRAM MUST USE A LOOP FOR ANY VALIDATION (so that it does not go on until the most dim-witted or clumsy user enters a valid number). 

·        Use doubles for anything that COULD be a non-whole number (e.g. daily rainfall amounts, ...)

·        This is an exercise in writing and using arrays. There are parts of the program that cannot be done without arrays.  It is also an exercise in using for loops; use a for loop (instead of other kinds of loops) for any COUNTER-CONTROLLED loop.   

·        You will still need the Keyboard file (still obtainable from my WWW page  - or you may still have it on disk). 

·        Format the data so that scores have two decimal places!!!  Please make neat columns by using something like:

        DecimalFormat twoDecFormat = new DecimalFormat ("0.00");

                              Instead of what we have been using, which drops trailing zeros

·        Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */). 

·        Also, comment any significant code to document it (each loop, each if, and each significant calculation should have a comment).

·        Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line). 

 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any set of inputs (test it on more than the example below!!, I will!!).

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Hand in:

 

 


Sample Interaction:

How many days rainfall will be logged in this batch?

1

I'm sorry, please enter a number between 2 and 100

How many days rainfall will be logged in this batch?

5

Day 1 Rainfall (in inches):

1.3

Day 2 Rainfall (in inches):

10.5

I'm sorry, please enter a value between 0 and 10.0

Day 2 Rainfall (in inches):

1.05

Day 3 Rainfall (in inches):

0.0

Day 4 Rainfall (in inches):

0.0

Day 5 Rainfall (in inches):

0.1

Mean Daily Rainfall (in inches): 0.49

 

Daily Rainfall Report:

      Day         Amount      Greater Than Mean

       1            1.30            *

       2            1.05            *

       3            0.00            

       4            0.00            

       5            0.10