import java.io.*;
import javagently.*;

class Summation2 {

  /* The Second Summation program   by J M Bishop Aug 1996
   * ----------------------------   Java 1.1 October 1997
   *
   * Reads in numbers from a file and display their sum.
   * Illustrates the declaration of input from both
   * the keyboard and a file. 
   */

  public static void main (String [] args) throws IOException {
        
    int count;
    double total = 0; 
    double number; 

    BufferedReader in = Text.open(System.in); 
    BufferedReader fin = Text.open("numbers.dat");      

    System.out.println("****** Summing numbers from a file ******");
    
    Text.prompt ("How many numbers?");
    count = Text.readInt(in);

    for (int i = 1; i <= count; i++) {
       number = Text.readDouble(fin);
       total += number;
    }
    System.out.println("That's enough, thanks.");
    System.out.println("The total is "+total);
  }
}

