LinesAndPoints.java
contents ::
  Line.java
  LinesAndPoints.java
  text

/*         James Little wednesday 7th March 2001
Lines and points
*/
package jlittle_ex1;

import basicIO.*;

public class LinesAndPoints {

private static long [] xCoOrdinates, yCoOrdinates;


public static void main(String [] args) {
   int count = 1;
   int sent =0;
   int pointNumber = 0;
   int temp = 0;



   while (In.readLine() != null) {
       // set array index
       if(In.countTokens()==1){         // entry only valid if there is only one token
            temp=In.getInt();
            if((temp>=2)&&(temp<=19)){
                pointNumber=temp;
            }else{
                System.out.println("Error : Sorry only reasonable input for the \"number of points\" should apply. Program terminated.");
                System.exit(-1);
            }

            // initialize arrays
            xCoOrdinates = new long[pointNumber];
            yCoOrdinates = new long[pointNumber];
       }else if(In.countTokens()>1){
            System.out.println("Error : Wrong number of entries for point number. Program terminated.");
            System.exit(-1);
       }else{
            System.out.println("Error: invalid input... not enough points.");
            System.exit(-1);
       }// end if
            
       
       // read points into  x and y arrays
       for(int i=0; i<pointNumber; i++) {
            In.readLine();
            if(In.countTokens()==2){         // entry only valid if two tokens on line

                temp = In.getInt();
                if((temp>=0)&&(temp<=99999)){
                     xCoOrdinates[i] = temp;
                }else{
                     // terminate program and reason for termination
                     System.out.println("Error : Input out of range (0-99999). Program terminated.");
                     System.exit(-1);
                }

                temp = In.getInt();
                if((temp>=0)&&(temp<=99999)){
                     yCoOrdinates[i] = temp;
                }else {
                     // terminate program and reason for termination
                     System.out.println("Error : Input out of range (0-99999). Program terminated.");
                     System.exit(-1);
                }
            }else{
                // terminate program and reason for termination
                System.out.println("Error : Not enough points. Program terminated.");
                System.exit(-1);
            }
       }// end for loop

       // send messages
       int segments = pointNumber-1;
       
       Line l = new Line(segments, count, xCoOrdinates, yCoOrdinates);
       l.think();
       // count just keeps track of the line number
       count++;
   } // end while loop         

   System.out.println("END OF OUTPUT");

}// end main method
                  
}// end class


James Little