AppCheck.java
contents ::
  addmod
  AppCheck.java
  CheckDigits.java
  ex3.data
  ex3.expected
  indata
  letters

/*
  James Little
  17/3/01 - Exercise 3 - cosc 241
  Program to check ISBN numbers
*/

package jlittle_ex3;
import basicIO.*;

public class AppCheck {

    public static void main(String [] args){
         CheckDigits cd;
         int [] isbnten = new int [10];   // int array to store valid digits
         int z=0;                         // z will keep count of ChecDigits array indexs
         int count=0;                     // count wil prevent int array from throwing an out of range error
         boolean possible=false;          // is it possble that this is an isbn number? 
         

         while (In.readLine() != null) {  // get input
             count=0;                     // set count to zero at beginning of each new line

             // very local variables
             String isbn=In.getLast();    // get the line back 
             int charvalue=0;             // what value are you?

             if(isbn.length()>0){         // if its less than 1 its not an isbn
                  possible=true;           // data valid unless proven invalid!
                  for(int i=0; i<isbn.length(); i++) {
                  
                      charvalue=(int) isbn.charAt(i); // convert char to int
                      if(count<10){        // if its 10, its actually 11, and its not an isbn
                           if((charvalue==88)&&(count==9)){// if X is the last 
                               isbnten[count]=10; // X == 10, not 88 sorry unicode.
                               count++;     // add one to count
                          }else if((charvalue==120)&&(count==9)){// if X is the last 
                               isbnten[count]=10; // x == 10, not 120 sorry unicode.
                               count++;     // add one to count
                              
                           }else if((charvalue>47)&&(charvalue<58)){  // is it a valid number?
                               isbnten[count]=charvalue-48; // number is unicode value - 48, honest
                               count++;     // add one to count
                           }else if(charvalue==45); // unlimited '-'
                           else possible=false; // otherwise its not isbn, end if
                      }else if(charvalue==45); // unlimited '-'
                      else possible=false; //ditto,  end if
                  
                  }// end for
             }else {
                  count=0;                 // if 0...
                  possible=false;          // not isbn
             }
             if((count==9||count==10)&&(possible)){  // if count is 9 or 10
                  cd = new CheckDigits(isbnten,count,isbn);  // then send data to CheckDigits class
                  cd.displayData();     // view info
                  
             }else{
                  // when count was less than 10, it escaped my net.. so set possible to false here
                  possible=false;
                  cd = new CheckDigits(isbn, possible);  // send data to the not possible constructor
                  cd.displayData();     

             }// end if
         } // end while

         // program main output
         Out.println("END OF OUTPUT");    // thats all folks
    }// end main
}// end class AppCheck

James Little