Error Message when reading an input file.
Hello all, I keep getting an error when I am trying to read in a word from an input file. This is the code, the error and the input file. I know some of the things in the worker class aren't all updated with what I need to do my calculations, but I am just looking to get it to print the string. Thanks
package GroupProject;
import java.io.*;
import java.util.Scanner;
import java.text.NumberFormat;
public class GroupProject
{
public static void main(String[] args) throws IOException
{
// Declare variables
int num1, num2, num3;
double fee;
double totalFee=0;
String dest;
// Build the scanner object
Scanner fileScan = new Scanner(new File("manifest.inp"));
// Print a message to the user explaining what the program does
System.out.println("This program calculates fees for leaving a car or truck in a parking garage.");
NumberFormat fmt = NumberFormat.getCurrencyInstance();
// Read in data from file
while (fileScan.hasNext())
{
dest = fileScan.nextLine();
num1 = fileScan.nextInt();
num2 = fileScan.nextInt();
num3 = fileScan.nextInt();
passenger Calculator = new passenger(dest, num1, num2, num3);
fee=Calculator.calcFees();
System.out.println(Calculator);
totalFee+=fee;
}
System.out.println("The day's total fees are:" +fmt.format(totalFee));
}
}
package GroupProject;
import java.text.NumberFormat;
public class passenger
{
// instance data
private int luggage, time, base;
private double sum = 0;
String going;
// constructor
public passenger(String dest, int num1, int num2, int num3)
{
luggage = num1;
time = num2;
base = num3;
dest = going;
}
public double calcFees()
{
switch(luggage)
{
case 1:
sum += 15;
break;
case 2:
sum += 30;
break;
}
switch(time)
{
case 1:
sum += 0;
break;
case 2:
sum += 50;
break;
case 3:
sum += -20;
break;
}
switch(base)
{
case 1:
sum += 10;
break;
case 2:
sum += 25;
break;
case 3:
sum += 50;
break;
}
return sum;
}
// toString method
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String info = "The cost for this vehicle is: " +fmt.format(sum)+ " and they are headed to " +going;
return info;
}
}
Exception in thread "main" java.util.NoSuchElementException
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 GroupProject.GroupProject.main(GroupProject.java:3 2)
LosAngelas
2 2 2