Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Paths;
  5. import java.util.NoSuchElementException;
  6. import java.util.Scanner;
  7.  
  8. public class Main
  9. {
  10.  
  11.     private Scanner input;
  12.  
  13.     public static void main(String[] args)
  14.     {
  15.         developerInfo();
  16.         Main myObject = new Main();
  17.  
  18.         myObject.openFile();
  19.  
  20.     }
  21.  
  22.  
  23.     public void openFile()
  24.     {
  25.         try
  26.         {
  27.             input = new Scanner(Paths.get("Program6.txt"));
  28.         }
  29.         catch (IOException ioException)
  30.         {
  31.             System.err.println("Error opening file. Terminating.");
  32.             System.exit(1);
  33.         }
  34.     }
  35.  
  36.  
  37.     // Read records from the file
  38.     public void readRecords()
  39.     {
  40.         try
  41.         {
  42.             while (input.hasNext()) // while there is more to read
  43.             {
  44.                 // display record contents
  45.                 System.out.printf("%10.2f%n", input.nextDouble());
  46.             }
  47.         }
  48.         catch (NoSuchElementException elementException)
  49.         {
  50.             System.err.println("File improperly formed. Terminating.");
  51.         }
  52.         catch (IllegalStateException stateException)
  53.         {
  54.             System.err.println("Error reading from file. Terminating.");
  55.         }
  56.     }
  57.     public static void developerInfo()
  58.     {
  59.         System.out.println ("Name:    Jon Elliott");
  60.         System.out.println ("Course:  ITSE 2321 Object-Oriented Programming");
  61.         System.out.println ("Program: Four \n");
  62.  
  63.     } // End of developerInfo
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement