I am trying to read a file with three different items. When I run it I get the first three items printed but I can't seem to get it to run back through the loop.
The file reads as below:
Tom Atto
6
3
Eaton Wright
5
5
Cary Oki
5
11
The file will read the first line three lines and prints:
The ideal weight for Tom Atto is: 185.
Then it has an error:
Input has information to read? true
The ideal weight for Tom Atto is: 185.0
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at chapter3.chapterThreeProject12.main(chapterThreeProject12.java:38)
The code I have written:
```java
//import file
Scanner fileIn = null;
Scanner keyboard = new Scanner(System.in);
try {
fileIn = new Scanner(new FileInputStream("/Users/nicola/Desktop/file2.txt"));
}
catch (FileNotFoundException e) {
System.out.println("File not found");
System.exit(0);
}
//end import
String name1;
double heightFeet1, heightInch1;
int count = 1;
System.out.println("Input has information to read? " + fileIn.hasNext());
while (fileIn.hasNext()) {
name1 = fileIn.nextLine();
heightFeet1 = fileIn.nextDouble();
heightInch1 = fileIn.nextDouble();
double height1 = (heightFeet1 * 12 )+ heightInch1;
double calculatingHeight1 = (height1 - 60);
double idealWeight1 = (calculatingHeight1 * 5) + 110;
System.out.println("The ideal weight for " + name1 + " is: " + idealWeight1);
}