public class CityTemps
{
    public static void main (String []
args)
    {
        City ourCity
= new City ();
        ourCity.readTemps
();
        ourCity.displayTemps
();
        ourCity.storeTemps
();
    }
} // class CityTemps
class City
{
    private final int maxSize = 20;
    private int [] highTemps, lowTemps;
    private int listSize;
    City ()
    {
        listSize =
0;
        highTemps
= new int [maxSize];
        lowTemps =
new int [maxSize];
    } // constructor
    public void readTemps ()
    {
        System.out.print
("File Name: ");
        String fileName
= Reader.readString ();
        try
        {
           
BufferedReader infile = new BufferedReader
               
(new InputStreamReader (new FileInputStream (fileName)));
           
int count = 0;
           
String highString = infile.readLine ();
           
while (highString != null)
           
{
               
highTemps [count] = Integer.parseInt (highString);
               
lowTemps [count] = Integer.parseInt (infile.readLine ());
               
count ++;
               
highString = infile.readLine ();
           
} // while
           
listSize = count;
           
infile.close ();
        } catch (IOException
e)
        { System.out.println
("File not found.");};
    } // method readTemps
    private int calculateAverage (int high,
int low)
    {
        return (high
+ low) / 2;
    } // method calculateAverage
    public void displayTemps ()
    {
        System.out.println
("The city\'s temperatures.");
        for (int count
= 0; count < listSize; count++)
        {
           
int average = calculateAverage (highTemps [count], lowTemps [count]);
           
System.out.println ("High: " + highTemps [count] + " Low: " + lowTemps
[count]
               
+ " Average: " + average);
        }
    } // method displayTemps
    public void storeTemps ()
    {
        System.out.print
("File Name: ");
        String fileName2
= Reader.readString ();
        try
        {
           
PrintWriter outfile = new PrintWriter (new FileWriter (fileName2));
           
for (int count = 0; count < listSize; count++)
           
{
               
int average = calculateAverage (highTemps [count], lowTemps [count]);
               
outfile.println (highTemps [count]);
               
outfile.println (lowTemps [count]);
               
outfile.println (average);
           
}
           
outfile.close ();
        } catch (IOException
e) {}
    } // method storeTemps
} // class City