previous | start | next

File InputTest.java

1 import java.util.StringTokenizer;
2 import javax.swing.JOptionPane;
3
4 /**
5     This program computes the average and maximum of a set
6     of input values that are entered on a single line.
7 */
8 public class InputTest
9 {  
10    public static void main(String[] args)
11    {  
12       DataSet data = new DataSet();
13
14       String input = JOptionPane.showInputDialog("Enter values:");
15       StringTokenizer tokenizer = new StringTokenizer(input);
16       while (tokenizer.hasMoreTokens())
17       {  
18          String token = tokenizer.nextToken();
19    
20          double x = Double.parseDouble(token);
21          data.add(x);
22       }
23
24       System.out.println("Average = " + data.getAverage());
25       System.out.println("Maximum = " + data.getMaximum());
26    }
27 }


previous | start | next