// 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()
);
}
}