| 1 | import javax.swing.JOptionPane; |
| 2 | |
| 3 | /** |
| 4 | This program computes the average and maximum of a set |
| 5 | of input values. |
| 6 | */ |
| 7 | public class InputTest |
| 8 | { |
| 9 | public static void main(String[] args) |
| 10 | { |
| 11 | DataSet data = new DataSet(); |
| 12 | |
| 13 | boolean done = false; |
| 14 | while (!done) |
| 15 | { |
| 16 | String input = JOptionPane.showInputDialog("Enter value, Cancel to quit"); |
| 17 | if (input == null) |
| 18 | done = true; |
| 19 | else |
| 20 | { |
| 21 | double x = Double.parseDouble(input); |
| 22 | data.add(x); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | System.out.println("Average = " + data.getAverage()); |
| 27 | System.out.println("Maximum = " + data.getMaximum()); |
| 28 | } |
| 29 | } |