Computer Science 121
Example using a StringTokenizer and an array.

import java.io.*;
import java.util.*;

// This application finds the average high temperature and highest temperature for a week.
public class Weather
{
    public static void main (String [] args)
    {
        WeeksWeather week = new WeeksWeather ();
        week.readTemperatures ();
        week.displayStatistics ();
    } // main method
} // class Weather

/* This class reads high temperatures into an array of integers. It then calculates the average temperature and displays the result on the screen. */
class WeeksWeather
{
    int [] highs;
    int numberTemps;

    WeeksWeather ()
    {
        numberTemps = 0;
        highs = new int [10];
    } // constructor

    public void readTemperatures ()
    {
        int temperature;
        BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
        try
        {
            System.out.println ("Enter high temperatures on one line.");
            String temperatureString = stdin.readLine ();
            StringTokenizer temperatureList = new StringTokenizer (temperatureString);
            while (temperatureList.hasMoreTokens ())
            {
                temperature = Integer.parseInt (temperatureList.nextToken ());
                highs [numberTemps] = temperature;
                numberTemps ++;
            }
        } // try block
        catch (IOException e) { System.out.println ("IO Exception");}
        catch (NumberFormatException ex) { System.out.println ("Number format error.");}
    } // method readTemperatures

    private int calculateAverage ()
    {
        int sum = 0;
        for (int count = 0; count < numberTemps; count ++)
            sum = sum + highs [count];
        int average = sum / numberTemps;
        return average;
    } // method calculateAverage

    private int findHighest ()
    {
        int highest, location;
        highest = highs [0];
        for (int count = 1; count < numberTemps; count ++)
        {
            if (highest < highs [count])
                highest = highs [count];
        }
        return highest;

    } // method findHighest

    public void displayStatistics ()
    {
        int average = calculateAverage ();
        int highest = findHighest ();
        System.out.println ("The average high was " + average);
        System.out.println ("The highest temperature was " + highest);
    } // method displayAverage
} // class WeeksWeather