# Java Notes

# Rainfall user interface - Console

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
    // RainfallScanner.java - Condole user interface to RainfallStats
    // This separates the user interface from the "model"
    //      or "business logic".  Such separation is
    //      required in larger programs to keep them
    //      readable, altho in this small program it
    //      is only used to illustrate the idea.
    // Fred Swartz - Nov 29 2005

    import java.util.*;

    public class RainfallScanner {

        public static void main(String[] args) {
            //... Initializations
            String prompt = "Enter rainfall measurements.  Non-number stops.";
            Scanner in = new Scanner(System.in);
            RainfallStats rainData = new RainfallStats();

            System.out.println(prompt);

            //... Read in and accumulate data.
            while (in.hasNextDouble()) {
                double rain = in.nextDouble();
                rainData.add(rain);
            }

            //... Print the results.
            System.out.println(
                       "Total rain = "   + rainData.getTotal() + "\n"
                     + "Average rain = " + rainData.getAverage()
                     );
        }
    }