title: While loop with hasNext(); not fully looping
body: <p>I'm in the process of creating a program that reads data from an external file, compares it with other data within the file then prints the results to a new external file. I am having problems with the while loop section of my code. I am unsure whether it is the while loop itself or the for loop which is nested within. Here is the code:</p>
  
  <pre><code>public class WageCalculator {
  
    public static void main(String[] args) throws FileNotFoundException {
  
      Scanner input = new Scanner(new FileReader("TestData.txt")); //Scanner for external file
      PrintWriter output = new PrintWriter("wagedaily.txt");
  
      float RecommendedMaximum;
      RecommendedMaximum = Float.parseFloat(JOptionPane.showInputDialog(null, "Enter the recommended maximum journey cost:"));
  
      String ShipID, JourneyID; //Variables
      int JourneyLength, Crew;
      double RateOfPay, CrewCost, TotalCost;
  
      while (input.hasNext()) { //EOF-Controlled While Loop
        ShipID = input.nextLine();
        JourneyID = input.nextLine();
        JourneyLength = input.nextInt();
        Crew = input.nextInt();
  
        CrewCost = 0; //Default Values Set
        TotalCost = 0;
        for (int x = Crew; x &gt; 0; x--) { //For Loop updates the above values
          RateOfPay = input.nextDouble();
          CrewCost = RateOfPay * JourneyLength;
          TotalCost = TotalCost + CrewCost;
        }
  
        if (TotalCost &lt; RecommendedMaximum) { //if-else statements to compare values
          System.out.println("The total cost of...");
          output.println("The total cost of...");
        } else if (TotalCost == RecommendedMaximum) {
          System.out.println("The total cost of...");
          output.println("The total cost of...");
        } else {
          System.out.println("The total cost of...");
        }
      }
  
      output.close(); //Close both Scanner and Printwriter
      input.close();
    }
  
  }
  </code></pre>
  
  <p>The error I get is this:  </p>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException  
  at java.util.Scanner.throwFor(Unknown Source)  
  at java.util.Scanner.next(Unknown Source)  
  at java.util.Scanner.nextInt(Unknown Source)  
  at java.util.Scanner.nextInt(Unknown Source)  
  at (package).WageCalculator.main(WageCalculator.java:30)
  </code></pre>
  
  <p>The error says it's line 30 in my code that is the problem but I am not so sure.</p>
  
  <p>Incase anyone needs to see the TestData.txt file:</p>
  
  <pre><code>Monarch  //ShipID
  M141     //JourneyID
  16       //JourneyLength
  6        //Crew
  10.5     //RateOfPay -
  10.5
  20
  20
  20
  30       //- RateOfPay
  Princess //ShipID
  P103     //JourneyID
  18       //JourneyLength
  5        //Crew
  40       //RateOfPay -
  45
  45
  60
  80       //- RateOfPay
  </code></pre>
  
  <p>Any help would be appreciated :) </p>