All pastes #808354 Raw Edit

Consultation

public java v1 · immutable
·published 2007-12-07 14:18 UTC
rendered paste body
import java.io.File;import java.io.FileNotFoundException;import java.lang.IllegalStateException;import java.util.NoSuchElementException;import java.util.Scanner;public class Consultation{   private Scanner input;   // enable user to open file   public void openFile()   {      try      {         input = new Scanner( new File( "A:\\SmartCard.txt" ) );      } // end try      catch ( FileNotFoundException fileNotFoundException )      {         System.err.println( "Error opening file." );         System.exit( 1 );      } // end catch   } // end method openFile   // read record from file   public void readRecords()   {      // object to be written to screen      octopusRecord record = new octopusRecord();	System.out.printf("\t\t\tConsultation\n");      System.out.printf( "%-10s\t%-20s\t%-12s\t%10s\n", "Type",         "Name", "Value", "PayRecord" );      try // read records from file using Scanner object      {         while ( input.hasNext() )         {            record.setType( input.nextLine() ); // read account number            record.setName( input.nextLine() ); // read first name            record.setValue( input.nextDouble() ); // read last name            record.setPayRecord( input.nextLine() ); // read balance           // load sounds and set currentSound          			System.out.printf( "%-10s\t%-12s\t\t%-10.2f\t Passed-in      ",               record.getType(), record.getName(),               record.getValue());//, record.getPayRecord());         } // end while      } // end try      catch ( NoSuchElementException elementException )      {         System.err.println( "File improperly formed." );         input.close();         System.exit( 1 );      } // end catch      catch ( IllegalStateException stateException )      {         System.err.println( "Error reading from file." );         System.exit( 1 );      } // end catch   } // end method readRecords   // close file and terminate application   public void closeFile()   {      if ( input != null )         input.close(); // close file   } // end method closeFile      public static void main(String arg[]) {		Consultation consultation = new Consultation();				consultation.openFile();		//open method from Consultation.java		consultation.readRecords();		consultation.closeFile();			}// end main method} // end class ReadTextFile